Binary Search to Find Next Greater Element V
You can use the .BinarySearch method of List<T>. It works well, there is a bit of a trick that you need to do when the return index is negative (just assign it to its complement, ~index). No need to perform the Binary Search "by hand" anymore. Achieves a good NLogN, fast solution. LC suggests a Tree to be used but this approach (two lists, one for even, one for odd) works well. Code is down below, cheers, ACC. Count Smaller Elements With Opposite Parity - LeetCode You are given an integer array nums of length n . The score of an index i is defined as the number of indices j such that: i < j < n nums[j] < nums[i] nums[i] and nums[j] have different parity (one is even and the other is odd). Return an integer array answer of length n , where answer[i] is the score of index i . Example 1: Input: nums = [5,2,4,1,3] Output: [2,1,2,0,0] Explanation: Fo...