simple bfs problem. the one thing you have to take care is the disjoint groups in the graph.. i got a wrong answer for printing
No Suspicious bugs found! instead of
No suspicious bugs found!..
i’m in the grey area for 2 days, unable to figure out what is wrong about the algo. the algo is to maintain two priority queues(with different orders) of equal sizes or a +1 diff. and print the median. but i got fixated on sizes and forgot about rearranging the elements.
simple one, after you get to know about the Fermat’s Theorem…. and also if
n = 4*k + 3, it can never be a sum of two squares.
even^2 + even^2 = 4*k
odd^2 + even^2 = 4*k + 1
odd^2 + odd^2 = 4*k + 2
Fermat’s Theorem: A number n is a sum of two squares if and only if all prime factors of n of the form 4m+3 have even exponent in the prime fatorization of n.
at last! i’m able to solve it.
this is really a tricky question but simple one.
just another simple question..
F(lo, hi) = 0 if hi - lo < 1
= arr[lo] if hi - lo == 1
= max(arr[lo] + F(lo + 2), F(lo + 1, hi)) if hi - lo > 1
just another simple combinatorics problem. but i don’t why i’m getting a Runtime error for a python solution, but atlast i did that with C++