@1337c0d3r Link is not working. Kindly fix it.
dilip7
@dilip7
Posts made by dilip7

RE: A Recursive Approach to Segment Trees, Range Sum Queries & Lazy Propagation

RE: Easiest 2ms Java Solution
@BVBSC Yes, so if the grandparent is not the root of the tree then in that case as well, u reduce the number of nodes you are visiting to reach the parent.
I believe that this is confusing as you are thinking that we directly store parent node of current node which is not the case always unless grandparent is indeed the parent.
HTH.

RE: Easiest 2ms Java Solution
Here if we don't write roots[id] = roots[roots[id]] (which is path compression) then every time we call find for id, we are traversing parent tree till root, but by writing this line we are reducing path to parent. That means we have reduced path to reach parent of current id, Hence this is called path compression.
If it's still not clear then take a sample graph and see how parent array is different with and without path compression.
HTH.

My solution based on enumeration of bits
based on https://www.topcoder.com/blog/generatingcombinations/
public class Solution { public List<List<Integer>> combine(int n, int r) { List<List<Integer>> ls = new ArrayList<>(); for(int i=0; i<(1<<n);i++){ if(Integer.bitCount(i)==r){ // System.out.println("> "+ i ); List<Integer> temp = new ArrayList<>(); // temp.add(i); for(int j=0;j<32;j++){ // System.out.println("j>> "+ j); if((i & (1<<j)) != 0 ){ // System.out.println("Bit is set at " + (j)); temp.add(j+1); } } ls.add(temp); } } return ls; } }
I am unsure if this will always give the correct answer for all combinations as currently, I iterate through only 32 bits for integer.