Back to problems

Count of Smaller Numbers After Self

Algorithm · ByteDance · Hard

You are given an integer array nums. Build and return an array counts of the same length. For every position i, counts[i] is how many elements located after index i (that is, at indices j > i) have a value strictly less than nums[i]. Input format: the first line contains the length n. The second line contains the n values of nums, separated by spaces. Output format: print the n entries of counts on one line, separated by spaces. Example 1: Explanation: To the right of 5 are…

Loading the rest of the question…