I don't have any complaints with your explanation. You are a great problem solver. Watching multiple times clears the doubts. But as an experienced developer I hope you incorporate this suggestion -> CHOOSE PROPER NAMING CONVENTIONS WHICH ARE SELF EXPLANATORY.
can you figure out why it isn't working, Lexicographically Maximal Prefix AND problem #include using namespace std; int referenceValue; bool comp(int a, int b) { for (int i = 31; i >= 0; i--) { if ((1 t; while (t--) { int n; cin >> n; vector ar(n); for (int i = 0; i < n; i++) { cin >> ar[i]; } sort(ar.begin(), ar.end(),greater()); // descending sort referenceValue = ar[0]; if (n > 1) { sort(ar.begin() + 1, ar.end(), comp); } cout
You know even i did same but it won't work suppos the second number after sorting has unset some bits now instead of this number we are still focusing on original number
@@himanshu_27tt take Eg 15 10 4 2 in this case our sorting won't work (write binary represenation of this example and try to apply your logic) credit: @ayushkandpal4600
@@himanshu_27tt Take this case 15 10 4 2 try to apply our algorithm: we will get sorted order as 15 10 4 2 but actual order should be 15 10 2 4 credits: @ayushkandpal4600