MCQs
The method toBinaryString() takes an integer argument and is defined in java.lang package. Usage is java.lang.Integer.toBinaryString(int) this returns the string representation of the unsigned integer value.
Whenever a '(' is encountered, push it into the stack, and when a ')' is encountered check the top of the stack to see if there is a matching '(', if not return false, continue this till the entire string is processed and then return true.
All the characters in the string have to be processed, hence the complexity is O(n).
Since each time you are halving the number, it can be related to that of a binary search algorithm, hence the complexity is O(logn).
Here instead of adding the digits to an array, you push it into a stack and while printing, pop it from the stack.
Stack is a convenient option as it involves pushing and popping of characters.
Tracing of the moves in the above ToH problem will prove this result, instead you can simply add a count for each recursive call to check the number of moves.
Although, it is possible to reverse the string without using stack, it is done by looping through the string from the end character by character.
In Java, it is also possible to use the StringBuilder and StringBuffer classes which have a built-in method 'reverse'.
Note its similarity to PalindromeTest
Push all the characters in the input string to a stack, now pop them and append to a new string which is checked for equality with the original string.
By definition, a palindrome is a string which is the same forward and backward, here, option d doesn't adhere to this definition.