Leetcode - First Unique Character in a String


Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.


s = "leetcode"
return 0.

s = "loveleetcode",
return 2.


Leetcode - Counting Elements

Given an integer array arr, count element x such that x + 1 is also in arr.

If there're duplicates in arr, count them seperately.


Example 1:

Input: arr = [1,2,3]
Output: 2
Explanation: 1 and 2 are counted cause 2 and 3 are in arr.


Leetcode - Compare Strings by Frequency of the Smallest Character


Let's define a function f(s) over a non-empty string s, which calculates the frequency of the smallest character in s. For example, if s = "dcce" then f(s) = 2 because the smallest character is "c" and its frequency is 2.

Now, given string arrays queries and words, return an integer array answer, where each answer[i] is the number of words such that f(queries[i]) < f(W), where W is a word in words.


Example 1:

Input: queries = ["cbd"], words = ["zaaaz"]
Output: [1]
Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").


Leetcode - Group Anagrams


Given an array of strings, group anagrams together.


Input: ["eat", "tea", "tan", "ate", "nat", "bat"],


Leetcode - Corporate Flight Bookings


There are n flights, and they are labeled from 1 to n.

We have a list of flight bookings.  The i-th booking bookings[i] = [i, j, k] means that we booked k seats from flights labeled i to j inclusive.

Return an array answer of length n, representing the number of seats booked on each flight in order of their label.


Example 1:

Input: bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
Output: [10,55,45,25,25]


Leetcode - Largest Unique Number


Given an array of integers A, return the largest integer that only occurs once.

If no integer occurs once, return -1.


Example 1:

Input: [5,7,3,9,4,9,8,3,1]
Output: 8
The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it's the answer.


  1. 1 <= A.length <= 2000
  2. 0 <= A[i] <= 1000


Leetcode - how-many-numbers-are-smaller-than-the-current-number


Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

Return the answer in an array.


Example 1:

Input: nums = [8,1,2,2,3]
Output: [4,0,1,1,3]
For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). 
For nums[1]=1 does not exist any smaller number than it.
For nums[2]=2 there exist one smaller number than it (1). 
For nums[3]=2 there exist one smaller number than it (1). 
For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).


  • 2 <= nums.length <= 500
  • 0 <= nums[i] <= 100