Given an input array of unsorted integers. Write a code to find second smallest number in an array.
For example :
arr = {-1, 7, 1, 34, 18}
The second smallest number in this array is 1.
Given a decimal number, Write a java program to convert decimal to binary number.
For example :
Input : 4 , Output : 100
Input : 5 , Output : 101
Input : 10 , Output : 1010
Get minimum element from stack in O(1).
In this problem, we have to design a stack that supports push, pop, top, and retrieving the minimum element in constant time (O(1)).
push(x) — Push element x onto stack.
pop() — Removes the element on top of the stack.
top() — Get the top element.
getMin() — Retrieve the minimum element in the stack.
For example: Suppose, If we push the following elements in a stack.
9 ==> Top
1
2
3
Then if we call getMin() method, It should return 1 in O(1) (constant time).