← 返回 ibm 的题目列表Implement Queue Using Two Stacks; Find Kth Missing Positive Number
类型:online_judge
ibm
Implement Queue using Stacks
Implement a queue using two stacks. Implement the following operations:
push(x) - Push element x to the back of the queue.
pop() - Removes the element from in front of the queue and returns that element.
peek() - Get the front element.
empty() - Return whether the queue is empty.
Example:
Input:
5
push(1)
push(2)
peek() # Returns 1
pop() # Returns 1
empty() # Returns false
Constraints:
The number of operations will not exceed 100.
Can store elements in an empty stack.
Kth Missing Positive Number
Given an array arr of positive integers sorted in a strictly increasing order, and an integer k.
Find the kth positive integer that is missing from this array.
Example 1:
Input: arr = [2,3,4,7,11], k = 5
Output: 9
Explanation: The missing positive integers are [1,5,6,8,9,...]. The 5th missing positive is 9.
Constraints:
1 <= arr.length <= 1000
1 <= arr[i] <= 1000
1 <= k <= 1000
Note: arr is sorted in ascending order.
Example
Input
2
1 2 3 4 7 11
5