Coding Questions CAAS
Coding Questions CAAS
• You are given an integer array nums and you have to return a new counts array. The counts
array has the property where counts[i] is the number of smaller elements to the right of nums[i].
Example 1:
Example 2:
Example 3:
Constraints:
• Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j <
k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false.
Example 1:
Input: nums = [1,2,3,4,5] Output: true Explanation: Any triplet where i < j < k is valid.
Example 2:
Example 3:
Input: nums = [2,1,5,0,4,6] Output: true Explanation: The triplet (3, 4, 5) is valid because
nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
Constraints:
1 <= nums.length <= 5 * 105
Follow up: Could you implement a solution that runs in O(n) time complexity and O(1) space
complexity?
• Given a circularly sorted integer array, find a pair with a given sum. Assume there are no
duplicates in the array, and the rotation is in an anti-clockwise direction around an unknown
pivot.
For example,
• Given a string s and an integer k, return the length of the longest substring of s such that the
frequency of each character in this substring is greater than or equal to k.
Example 1:
Input: s = "aaabb", k = 3 Output: 3 Explanation: The longest substring is "aaa", as 'a' is repeated
3 times.
Example 2:
Constraints:
Note that in some languages, such as Java, there is no unsigned integer type. In this case, both
input and output will be given as a signed integer type. They should not affect your
implementation, as the integer's internal binary representation is the same, whether it is signed
or unsigned.
In Java, the compiler represents the signed integers using 2's complement notation. Therefore,
in Example 2 above, the input represents the signed integer -3 and the output represents the
signed integer -1073741825.
Example 1:
Example 2:
Constraints:
Follow up: If this function is called many times, how would you optimize it?
• Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water),
return the number of islands.
Example 1:
Example 2:
m == grid.length
n == grid[i].length
• Given an array of integers nums and an integer target, return indices of the two numbers such
that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the
same element twice.
Example 1:
Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] ==
9, we return [0, 1].
Example 2:
Example 3:
Constraints:
Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity?