1. Find Common Characters

    Description:

    Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.

    Solution:

    1. Using hash table
  2. Maximize Sum Of Array After K Negations

Description: Given an integer array nums and an integer k, modify the array in the following way. Return

Solution:

  1. Partition Array Into Three Parts With Equal Sum

    Description:

    Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.

    Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])

    Solution:

    1. Using prefix sum

      First we have to find if total sum divisible 3 (because we have to find 3 equal parts)

      Second, we have to find first part which equal to target ( where target = total/3)

      Then we keep find first 2 equal parts ( we do not need to check third one) while i+1 < j

      If we found first 2 equal parts ⇒ return true

      if not ⇒ return false;

  2. Binary Prefix Divisible By 5

    Description:

    You are given a binary array nums (0-indexed).

    We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).

    Return an array of booleans answer where answer[i] is true if xi is divisible by 5.

    Solution:

    1. Using Brute-force

      num = (num * 2 + nums[i]) % 5;

      This means take the current number, shift it left by 1 bit, add the new incoming bit, and keep only its remainder modulo 5.

      Because if we using sum ⇒ it might fail because the sum might be really big

  3. Remove Outermost Parentheses

    Description: A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.

    Solution 1: use count variable to check:

  4. empty

  5. empty

  6. empty

  7. emptu

  8. empty

  9. empty

  10. Sum of Root To Leaf Binary Numbers

    Description:

    You are given the root of a binary tree where each node has a value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit.

    For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these numbers.

    The test cases are generated so that the answer fits in a 32-bits integer.

    Solution:

    1. Using DFS
  11. Valid Boomerang

    Description: A boomerang is a set of three points that are all distinct and not in a straight line. Solution: use formula to find Area of triangle. If area = 0 ⇒ return false ,otherwise, return true.

  12. Greatest Common Divisor of Strings

Description:

For two strings s and t, we say "t divides s" if and only if s = t + t + t + ... + t + t (i.e., t is concatenated with itself one or more times).

Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

Solution:

  1. Occurrences After Bigram

    Description:

    Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.

    Return an array of all the words third for each occurrence of "first second third".

    Solution:

1103. Distribute Candies to People

Description:

We distribute some number of candies, to a row of n = num_people people in the following way:

We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.

Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and so on until we give 2 * n candies to the last person.

This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.  The last person will receive all of our remaining candies (not necessarily one more than the previous gift).

Return an array (of length num_people and sum candies) that represents the final distribution of candies.

Solution:

  1. Using brute-force ( using modulo to make circular array)

  2. Day of the Year

Description:

Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

Solution:

  1. Create calendar array with 12 months

  2. if leap year count++;

    Leap year is

    (year % 400) or (year % 100 ≠ 0 and year % 4)

    ⇒ Return count;