paradox dragon

I met three dragons. One always tells the truth, other one always lies and the last one alternates between lie and truth. Dragon 1: You may ask us one question, then you must guess which dragon is which Dragon 2: He’s lying. You may get three questions Dragon 3: Oh no. It’s definitely one question

Right Rotate an array by k elements

An array of elements is given arr arr is of length n Right rotate array by k elements Time complexity O(n) and space complexity O(1) Sample Input: arr = {1,2 ,3,4,5} n = 5 k = 2 Output : arr = {4,5,1,2,3}

Building a Stack with a getMax() function

Suppose you had a Stack class. Write a new class MaxStack which, in addition to push() and pop(), has a method getMax() which returns the largest item in the stack. Use your existing Stack class to store the stack’s contents. Don’t just use pop() to “dig” through your stack to find the max—do something that… Read More »