Skip to content

Commit 8df51b1

Browse files
committed
🚀 15-Aug-2020
1 parent 48bc1fb commit 8df51b1

5 files changed

+111
-2
lines changed

array/floor_of_num_in_sorted_array_binary_search.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ int getFloor(long long a[], int n, int x){
4949
mid=l+(h-l)/2;
5050
if(a[mid]==x){
5151
return mid;
52-
h=mid-1;
5352
}
5453
else if(a[mid]<x){
5554
res=mid; // possible result

array/kth_smallest_num_max_heap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/8
1+
/*
22
Given an array and a number k where k is smaller than size of array, we need to find the k’th smallest element in the given array. It is given that all array elements are distinct.
33
44
Example:

stack/min_stack_O(1).cpp

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
/*
2+
Design a data-structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. Your task is to complete all the functions, using stack data-Structure.
3+
4+
Input Format:
5+
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two lines. The first line of input contains an integer n denoting the number of integers in a sequence. In the second line are n space separated integers of the stack.
6+
7+
Output Format:
8+
For each testcase, in a new line, print the minimum integer from the stack.
9+
10+
Your Task:
11+
Since this is a function problem, you don't need to take inputs. You just have to complete 5 functions, push() which takes an integer x as input and pushes it into the stack; pop() which pops out the topmost element from the stack; isEmpty() which returns true/false depending upon whether the stack is empty or not; isFull() which takes the size of the stack as input and returns true/false depending upon whether the stack is full or not (depending upon the given size); getMin() which returns the minimum element of the stack.
12+
13+
Expected Time Complexity: O(1) for all the 5 functions.
14+
Expected Auxiliary Space: O(1) for all the 5 functions.
15+
16+
Constraints:
17+
1 <= T <= 100
18+
1 <= N <= 100
19+
20+
Example:
21+
Input:
22+
1
23+
5
24+
18 19 29 15 16
25+
Output:
26+
15
27+
*/
28+
29+
30+
31+
32+
33+
34+
35+
136
#include<iostream>
237
#include<stack>
338
using namespace std;

stack/min_stack_extra_space.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
/*
2+
Design a data-structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. Your task is to complete all the functions, using stack data-Structure.
3+
4+
Input Format:
5+
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two lines. The first line of input contains an integer n denoting the number of integers in a sequence. In the second line are n space separated integers of the stack.
6+
7+
Output Format:
8+
For each testcase, in a new line, print the minimum integer from the stack.
9+
10+
Your Task:
11+
Since this is a function problem, you don't need to take inputs. You just have to complete 5 functions, push() which takes an integer x as input and pushes it into the stack; pop() which pops out the topmost element from the stack; isEmpty() which returns true/false depending upon whether the stack is empty or not; isFull() which takes the size of the stack as input and returns true/false depending upon whether the stack is full or not (depending upon the given size); getMin() which returns the minimum element of the stack.
12+
13+
Expected Time Complexity: O(1) for all the 5 functions.
14+
Expected Auxiliary Space: O(1) for all the 5 functions.
15+
16+
Constraints:
17+
1 <= T <= 100
18+
1 <= N <= 100
19+
20+
Example:
21+
Input:
22+
1
23+
5
24+
18 19 29 15 16
25+
Output:
26+
15
27+
*/
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
141
#include<iostream>
242
#include<stack>
343
using namespace std;

stack/next_larger_element_in_array.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
/*
2+
Given an array A of size N having distinct elements, the task is to find the next greater element for each element of the array in order of their appearance in the array. If no such element exists, output -1
3+
4+
Input:
5+
The first line of input contains a single integer T denoting the number of test cases.Then T test cases follow. Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A.
6+
7+
Output:
8+
For each test case, print in a new line, the next greater element for each array element separated by space in order.
9+
10+
Constraints:
11+
1 <= T <= 100
12+
1 <= N <= 107
13+
1 <= Ai <= 1018
14+
Example:
15+
Input
16+
2
17+
4
18+
1 3 2 4
19+
4
20+
4 3 2 1
21+
Output
22+
3 4 4 -1
23+
-1 -1 -1 -1
24+
25+
Explanation:
26+
Testcase1: In the array, the next larger element to 1 is 3 , 3 is 4 , 2 is 4 and for 4 ? since it doesn't exist hence -1.
27+
*/
28+
29+
30+
31+
32+
33+
34+
35+
136
#include<bits/stdc++.h>
237
using namespace std;
338

0 commit comments

Comments
 (0)