8000 Merge branch 'master' into sambabib-js-solutions · sambabib/Leetcode@f9b9b6c · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f9b9b6c

Browse files
authored
Merge branch 'master' into sambabib-js-solutions
2 parents b7dc87f + efa91d4 commit f9b9b6c

File tree

50 files changed

+1876
-601
lines changed
  • cpp
  • paginated_contents
    • algorithms
      • 2nd_thousand
        • < 8000 div class="PRIVATE_TreeView-item-visual prc-TreeView-TreeViewItemVisual-dRlGq" aria-hidden="true">
          README.md
  • 3rd_thousand
  • 4th_thousand
  • database
  • python3
  • src
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    50 files changed

    +1876
    -601
    lines changed

    cpp/_916.cpp

    Lines changed: 34 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,34 @@
    1+
    class Solution {
    2+
    public:
    3+
    vector<string> wordSubsets(vector<string>& words1, vector<string>& words2) {
    4+
    int maxCharFreq[26] = {0};
    5+
    int tempCharFreq[26];
    6+
    for (const auto& word : words2) {
    7+
    memset(tempCharFreq, 0, sizeof tempCharFreq);
    8+
    for (char ch : word) {
    9+
    tempCharFreq[ch - 'a']++;
    10+
    }
    11+
    for (int i = 0; i < 26; ++i) {
    12+
    maxCharFreq[i] = max(maxCharFreq[i], tempCharFreq[i]);
    13+
    }
    14+
    }
    15+
    vector<string> universalWords;
    16+
    for (const auto& word : words1) {
    17+
    memset(tempCharFreq, 0, sizeof tempCharFreq);
    18+
    for (char ch : word) {
    19+
    tempCharFreq[ch - 'a']++;
    20+
    }
    21+
    bool isUniversal = true;
    22+
    for (int i = 0; i < 26; ++i) {
    23+
    if (maxCharFreq[i] > tempCharFreq[i]) {
    24+
    isUniversal = false;
    25+
    break;
    26+
    }
    27+
    }
    28+
    if (isUniversal) {
    29+
    universalWords.emplace_back(word);
    30+
    }
    31+
    }
    32+
    return universalWords;
    33+
    }
    34+
    };

    paginated_contents/algorithms/2nd_thousand/README.md

    Lines changed: 275 additions & 274 deletions
    Large diffs are not rendered by default.

    paginated_contents/algorithms/3rd_thousand/README.md

    Lines changed: 284 additions & 283 deletions
    Large diffs are not rendered by default.

    paginated_contents/algorithms/4th_thousand/README.md

    Lines changed: 72 additions & 41 deletions
    Large diffs are not rendered by default.

    paginated_contents/database/README.md

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,6 +6,7 @@
    66
    | 3059 |[Find All Unique Email Domains](https://leetcode.com/problems/find-all-unique-email-domains/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_3159.sql) || Easy |
    77
    | 3051 |[Find Candidates for Data Scientist Position](https://leetcode.com/problems/find-candidates-for-data-scientist-position/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_3051.sql) || Easy |
    88
    | 2990 |[Loan Types](https://leetcode.com/problems/loan-types/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2990.sql) || Easy |
    9+
    | 2879 |[Display the First Three Rows](https://leetcode.com/problems/display-the-first-three-rows/)| [Python3](https://github.com/fishercoder1534/Leetcode/blob/master/python3/2879.py) || Easy |
    910
    | 2205 |[The Number of Users That Are Eligible for Discount](https://leetcode.com/problems/the-number-of-users-that-are-eligible-for-discount/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2205.sql) || Easy |
    1011
    | 2082 |[The Number of Rich Customers](https://leetcode.com/problems/the-number-of-rich-customers/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2082.sql) || Easy |
    1112
    | 2072 |[The Winner University](https://leetcode.com/problems/the-winner-university/)| [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/database/_2072.sql) || Easy |

    python3/2879.py

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,4 @@
    1+
    import pandas as pd
    2+
    3+
    def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
    4+
    return employees.head(3)
    Lines changed: 22 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,22 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3270 {
    4+
    public static class Solution1 {
    5+
    public int generateKey(int num1, int num2, int num3) {
    6+
    String[] padded = new String[3];
    7+
    padded[0] = String.format("%04d", num1);
    8+
    padded[1] = String.format("%04d", num2);
    9+
    padded[2] = String.format("%04d", num3);
    10+
    StringBuilder sb = new StringBuilder();
    11+
    for (int i = 0; i < padded[0].length(); i++) {
    12+
    sb.append(
    13+
    Math.min(
    14+
    Character.getNumericValue(padded[0].charAt(i)),
    15+
    Math.min(
    16+
    Character.getNumericValue(padded[1].charAt(i)),
    17+
    Character.getNumericValue(padded[2].charAt(i)))));
    18+
    }
    19+
    return Integer.parseInt(sb.toString());
    20+
    }
    21+
    }
    22+
    }
    Lines changed: 25 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,25 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.HashSet;
    4+
    import java.util.Set;
    5+
    6+
    public class _3274 {
    7+
    public static class Solution1 {
    8+
    public boolean checkTwoChessboards(String coordinate1, String coordinate2) {
    9+
    return isBlack(coordinate2) == isBlack(coordinate1);
    10+
    }
    11+
    12+
    private boolean isBlack(String coordinate) {
    13+
    Set<Character> blackColsWithOddRows = new HashSet<>();
    14+
    blackColsWithOddRows.add('a');
    15+
    blackColsWithOddRows.add('c');
    16+
    blackColsWithOddRows.add('e');
    17+
    blackColsWithOddRows.add('g');
    18+
    if (blackColsWithOddRows.contains(coordinate.charAt(0))) {
    19+
    return Character.getNumericValue(coordinate.charAt(1)) % 2 == 1;
    20+
    } else {
    21+
    return Character.getNumericValue(coordinate.charAt(1)) % 2 == 0;
    22+
    }
    23+
    }
    24+
    }
    25+
    }
    Lines changed: 16 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,16 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3280 {
    4+
    public static class Solution1 {
    5+
    public String convertDateToBinary(String date) {
    6+
    String[] parts = date.split("-");
    7+
    StringBuilder sb = new StringBuilder();
    8+
    for (String part : parts) {
    9+
    sb.append(Integer.toBinaryString(Integer.parseInt(part)));
    10+
    sb.append("-");
    11+
    }
    12+
    sb.setLength(sb.length() - 1);
    13+
    return sb.toString();
    14+
    }
    15+
    }
    16+
    }
    Lines changed: 18 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,18 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.ArrayList;
    4+
    import java.util.List;
    5+
    6+
    public class _3285 {
    7+
    public static class Solution1 {
    8+
    public List<Integer> stableMountains(int[] height, int threshold) {
    9+
    List<Integer> ans = new ArrayList<>();
    10+
    for (int i = 1; i < height.length; i++) {
    11+
    if (height[i - 1] > threshold) {
    12+
    ans.add(i);
    13+
    }
    14+
    }
    15+
    return ans;
    16+
    }
    17+
    }
    18+
    }
    Lines changed: 20 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,20 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.HashSet;
    4+
    import java.util.Set;
    5+
    6+
    public class _3289 {
    7+
    public static class Solution1 {
    8+
    public int[] getSneakyNumbers(int[] nums) {
    9+
    int[] ans = new int[2];
    10+
    Set<Integer> set = new HashSet<>();
    11+
    int i = 0;
    12+
    for (int num : nums) {
    13+
    if (!set.add(num)) {
    14+
    ans[i++] = num;
    15+
    }
    16+
    }
    17+
    return ans;
    18+
    }
    19+
    }
    20+
    }
    Lines changed: 22 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,22 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3300 {
    4+
    public static class Solution1 {
    5+
    public int minElement(int[] nums) {
    6+
    int min = Integer.MAX_VALUE;
    7+
    for (int num : nums) {
    8+
    min = Math.min(min, findSum(num));
    9+
    }
    10+
    return min;
    11+
    }
    12+
    13+
    private int findSum(int num) {
    14+
    int sum = 0;
    15+
    while (num != 0) {
    16+
    sum += num % 10;
    17+
    num /= 10;
    18+
    }
    19+
    return sum;
    20+
    }
    21+
    }
    22+
    }
    Lines changed: 16 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,16 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3304 {
    4+
    public static class Solution1 {
    5+
    public char kthCharacter(int k) {
    6+
    StringBuilder sb = new StringBuilder("a");
    7+
    while (sb.length() <= k) {
    8+
    int n = sb.length();
    9+
    for (int i = 0; i < n; i++) {
    10+
    sb.append((char) (sb.charAt(i) + 1));
    11+
    }
    12+
    }
    13+
    return sb.charAt(k - 1);
    14+
    }
    15+
    }
    16+
    }
    Lines changed: 25 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,25 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.List;
    4+
    5+
    public class _3314 {
    6+
    public static class Solution1 {
    7+
    public int[] minBitwiseArray(List<Integer> nums) {
    8+
    int[] ans = new int[nums.size()];
    9+
    for (int i = 0; i < nums.size(); i++) {
    10+
    boolean found = false;
    11+
    for (int j = 1; j < nums.get(i); j++) {
    12+
    if ((j | (j + 1)) == nums.get(i)) {
    13+
    ans[i] = j;
    14+
    found = true;
    15+
    break;
    16+
    }
    17+
    }
    18+
    if (!found) {
    19+
    ans[i] = -1;
    20+
    }
    21+
    }
    22+
    return ans;
    23+
    }
    24+
    }
    25+
    }
    Lines changed: 59 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,59 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.HashMap;
    4+
    import java.util.Map;
    5+
    import java.util.PriorityQueue;
    6+
    7+
    public class _3318 {
    8+
    public static class Solution1 {
    9+
    public int[] findXSum(int[] nums, int k, int x) {
    10+
    PriorityQueue<int[]> maxHeap =
    11+
    new PriorityQueue<>(
    12+
    (a, b) ->
    13+
    a[1] != b[1]
    14+
    ? b[1] - a[1]
    15+
    : b[0] - a[0]); // a[0] is the number itself, a[1]
    16+
    // is the frequency
    17+
    Map<Integer, int[]> map = new HashMap<>();
    18+
    int i = 0;
    19+
    for (; i < k; i++) {
    20+
    int[] a = map.getOrDefault(nums[i], new int[2]);
    21+
    a[0] = nums[i];
    22+
    a[1]++;
    23+
    map.put(nums[i], a);
    24+
    }
    25+
    maxHeap.addAll(map.values());
    26+
    int[] ans = new int[nums.length - k + 1];
    27+
    for (int j = i - 1, p = 0; j < nums.length; ) {
    28+
    ans[p++] = computeTopX(new PriorityQueue<>(maxHeap), x);
    29+
    30+
    j++;
    31+
    if (j >= nums.length) {
    32+
    break;
    33+
    }
    34+
    int[] a = map.getOrDefault(nums[j], new int[2]);
    35+
    a[0] = nums[j];
    36+
    a[1]++;
    37+
    map.put(nums[j], a);
    38+
    39+
    a = map.getOrDefault(nums[j - k], new int[2]);
    40+
    a[0] = nums[j - k];
    41+
    a[1]--;
    42+
    map.put(nums[j - k], a);
    43+
    44+
    maxHeap.clear();
    45+
    maxHeap.addAll(map.values());
    46+
    }
    47+
    return ans;
    48+
    }
    49+
    50+
    private int computeTopX(PriorityQueue<int[]> maxHeap, int x) {
    51+
    int sum = 0;
    52+
    while (!maxHeap.isEmpty() && x-- > 0) {
    53+
    int[] a = maxHeap.poll();
    54+
    sum += a[0] * a[1];
    55+
    }
    56+
    return sum;
    57+
    }
    58+
    }
    59+
    }
    Lines changed: 29 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,29 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    import java.util.ArrayList;
    4+
    import java.util.List;
    5+
    6+
    public class _3324 {
    7+
    public static class Solution1 {
    8+
    public List<String> stringSequence(String target) {
    9+
    List<String> ans = new ArrayList<>();
    10+
    StringBuilder sb = new StringBuilder();
    11+
    for (char c : target.toCharArray()) {
    12+
    char candidate = 'a';
    13+
    boolean firstTime = true;
    14+
    do {
    15+
    if (firstTime) {
    16+
    firstTime = false;
    17+
    sb.append(candidate);
    18+
    } else {
    19+
    sb.setLength(sb.length() - 1);
    20+
    candidate = (char) (candidate + 1);
    21+
    sb.append(candidate);
    22+
    }
    23+
    ans.add(sb.toString());
    24+
    } while (c != candidate);
    25+
    }
    26+
    return ans;
    27+
    }
    28+
    }
    29+
    }
    Lines changed: 15 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,15 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3330 {
    4+
    public static class Solution1 {
    5+
    public int possibleStringCount(String word) {
    6+
    int ans = 1;
    7+
    for (int i = 1; i < word.length(); i++) {
    8+
    if (word.charAt(i) == word.charAt(i - 1)) {
    9+
    ans++;
    10+
    }
    11+
    }
    12+
    return ans;
    13+
    }
    14+
    }
    15+
    }
    Lines changed: 18 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,18 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3340 {
    4+
    public static class Solution1 {
    5+
    public boolean isBalanced(String num) {
    6+
    int oddSum = 0;
    7+
    int evenSum = 0;
    8+
    for (int i = 0; i < num.length(); i++) {
    9+
    if (i % 2 == 0) {
    10+
    evenSum += Character.getNumericValue(num.charAt(i));
    11+
    } else {
    12+
    oddSum += Character.getNumericValue(num.charAt(i));
    13+
    }
    14+
    }
    15+
    return oddSum == evenSum;
    16+
    }
    17+
    }
    18+
    }
    Lines changed: 24 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,24 @@
    1+
    package com.fishercoder.solutions.fourththousand;
    2+
    3+
    public class _3345 {
    4+
    public static class Solution1 {
    5+
    public int smallestNumber(int n, int t) {
    6+
    for (int num = n; ; num++) {
    7+
    int digitSum = getDigitsProduct(num);
    8+
    if (digitSum % t == 0) {
    9+
    return num;
    10+
    }
    11+
    }
    12+
    }
    13+
    14+
    private int getDigitsProduct(int num) {
    15+
    int copy = num;
    16+
    int product = 1;
    17+
    while (copy != 0) {
    18+
    product *= copy % 10;
    19+
    copy /= 10;
    20+
    }
    21+
    return product;
    22+
    }
    23+
    }
    24+
    }

    0 commit comments

    Comments
     (0)
    0