This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| // INTUITION: | |
| // to get the min. height, find the diameter of the graph (tree) | |
| // the middle node is your root of the min. height tree | |
| // if diameter of tree is of length: | |
| // odd: middle node in the diameter path is the only root node | |
| // that is possible that forms the min. tree hight | |
| // even: there are two root nodes possible that form the min. tree height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RangeFreqQuery { | |
| private int[] arr; | |
| private Map<Integer, Integer>[] segTree; | |
| public RangeFreqQuery(int[] arr) { | |
| this.arr = arr; | |
| segTree = new HashMap[4*arr.length]; | |
| buildSegTree(0, 0, arr.length - 1, arr, segTree); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Alice has some number of cards and she wants to rearrange the cards into | |
| // groups so that each group is of size groupSize, and consists of groupSize | |
| // consecutive cards. | |
| // Given an integer array hand where hand[i] is the value written on the ith | |
| // card and an integer groupSize, return true if she can rearrange the cards, or | |
| // false otherwise. | |
| // Example 1: | |
| // Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3 |