Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
10 views
5 pages
Interview Codes
interview preparation coding set
Uploaded by
babynamenestlings
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download
Save
Save Interview Codes For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
10 views
5 pages
Interview Codes
interview preparation coding set
Uploaded by
babynamenestlings
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Interview Codes For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Interview Codes For Later
You are on page 1
/ 5
Search
Fullscreen
1.
/* Interview Related Codes */
2.
3. class LIS {
4. public:
5. vector<int> arr;
6. vector<int> lis;
7. LIS(vector<int> input){
8. arr = input;
9. }
10.
11. void computeLIS()
12. {
13. for(int i=0; i<arr.size(); i++){
14. if(lis.empty()) lis.push_back(arr[i]);
15. else {
16. int maxElement = lis[(int)lis.size()-1];
17. if(arr[i] > maxElement) lis.push_back(arr[i]);
18. else {
19. int pos = lower_bound(lis.begin(), lis.end(), arr[i]) - lis.begin();
20. lis[pos] = arr[i];
21. }
22. }
23. }
24. }
25.
26. vector<int> findLIS()
27. {
28. computeLIS();
29. return lis;
30. }
31.
32. };
33.
34. class maxHeap {
35. private:
36. vector<int> heap;
37. int findParent(int idx){
38. return (idx-1)/2;
39. }
40. int findLeft(int idx){
41. return 2*idx+1;
42. }
43. int findRight(int idx){
44. return 2*idx+2;
45. }
46. void heapifyUp(int idx){
47. if(idx && heap[findParent(idx)] < heap[idx]){
48. swap(heap[findParent(idx)], heap[idx]);
49. heapifyUp(findParent(idx));
50. }
51. }
52. void heapifyDown(int idx){
53. int left = findLeft(idx);
54. int right = findRight(idx);
55.
56. int valid = idx;
57. if(left < findSize() && heap[left] > heap[idx]) valid = left;
58. if(right < findSize() && heap[right] > heap[idx]) valid = right;
59.
60. if(valid != idx){
61. swap(heap[idx], heap[valid]);
62. heapifyDown(valid);
63. }
64. }
65. public:
66. unsigned int findSize(){
67. return (unsigned int) heap.size();
68. }
69. bool isEmpty(){
70. return (findSize() == 0);
71. }
72. void push(int val){
73. heap.push_back(val);
74. int idx = findSize() - 1;
75. heapifyUp(idx);
76. }
77. void pop(){
78. heap[0] = heap.back();
79. heap.pop_back();
80. heapifyDown(0);
81. }
82. int top(){
83. return heap[0];
84. }
85. void prnt(){
86. cout << "myHeap ";
87. for(int i=0; i<heap.size(); i++) cout << heap[i] << " ";
88. cout << endl;
89. }
90. };
91.
92. class rollingHash{
93. public:
94. #define ll long long
95. string text, pattern;
96. ll base, MOD;
97. rollingHash(string givenText, string givenPattern, ll givenBase, ll givenMod){
98. text = givenText;
99. pattern = givenPattern;
100. base = givenBase;
101. MOD = givenMod;
102. }
103. ll kLengthPrefixHash(string &str, int k)
104. {
105. ll power = 1;
106. ll ans = 0;
107. for(int i=k-1; i>=0; i--){
108. ans = ans + (power*(str[i]-'a'))%MOD;
109. ans = ans%MOD;
110. power = (power*base)%MOD;
111. }
112. return ans;
113. }
114. ll powerFunction(ll x, ll y)
115. {
116. ll ans = 1;
117. for(int i=1; i<=y; i++) ans = (ans*x)%MOD;
118. return ans;
119. }
120. vector<int> findPositionMatch()
121. {
122. int len = (int) pattern.length();
123. ll hashValue = kLengthPrefixHash(pattern, len);
124. ll rollingHash = kLengthPrefixHash(text, len);
125. vector<int> answer;
126. answer.push_back(0);
127. ll power = powerFunction(base, len-1);
128. for(int i=len; i<text.length(); i++){
129. int prev_char = text[i-len]-'a';
130. int cur_char = text[i]-'a';
131. rollingHash = (rollingHash - (prev_char * power)%MOD + MOD)%MOD;
132. rollingHash = ((rollingHash*base)%MOD + cur_char)%MOD;
133. if(hashValue == rollingHash) answer.push_back(i-len+1);
134. }
135. return answer;
136. }
137. };
138.
139. class quickSort{
140. public:
141. int partitionIdx(vector<int> &arr, int l, int r)
142. {
143. int idx = l+1;
144. int pivot = arr[l];
145. for(int j=l+1; j<=r; j++){
146. if(arr[j] < pivot){
147. swap(arr[idx], arr[j]);
148. idx++;
149. }
150. }
151. swap(arr[l], arr[idx-1]);
152. return idx-1;
153. }
154.
155. void quick_sort(vector<int> &arr, int l, int r)
156. {
157. if(l < r){
158. int idx = partitionIdx(arr, l, r);
159. quick_sort(arr, l, idx-1);
160. quick_sort(arr, idx+1, r);
161. }
162. }
163. };
164.
165. class KMP{
166. public:
167. vector<int> prefix_function(string str)
168. {
169. int n = (int) str.length();
170. vector<int> pi(n);
171. pi[0] = 0;
172. for(int i=1; i<n; i++){
173. int j = pi[i-1];
174. while(j > 0 && str[i] != str[j]){
175. j = pi[j-1];
176. }
177. if(str[i] == str[j]) ++j;
178. pi[i] = j;
179. }
180. return pi;
181. }
182. };
183.
184. struct Point{
185. int x, y;
186. };
187.
188. class geometry{
189. public:
190. // Given three colinear points p, q, r, the function checks
191. // if point q lies on the segment 'pr'
192. bool onSegment(Point p, Point q, Point r){
193. if(q.x >= min(p.x, r.x) && q.x <= max(p.x, r.x) &&
194. q.y >= min(p.y, r.y) && q.y <= max(p.y, r.y)){
195. return true;
196. }
197. else return false;
198. }
199. // To find orientation of ordered triplet (p1, p2, p3)
200. // The function returns the following values
201. // 0 -> p, q, r are collinear
202. // 1 -> clockwise
203. // 2 -> counter clockwise
204. int orientation(Point p1, Point p2, Point p3){
205. int val = (p2.y - p1.y) * (p3.x - p2.x) - (p2.x - p1.x) * (p3.y - p2.y);
206. if(val == 0) return 0;
207. return (val > 0) ? 1:2;
208. }
209. bool doIntersect(Point p1, Point q1, Point p2, Point q2)
210. {
211. int o1 = orientation(p1, q1, p2);
212. int o2 = orientation(p1, q1, q2);
213. int o3 = orientation(p2, q2, p1);
214. int o4 = orientation(p2, q2, q1);
215.
216. if(o1 == 0 && onSegment(p1, p2, q1)) return true;
217. if(o2 == 0 && onSegment(p1, q2, p1)) return true;
218. if(o3 == 0 && onSegment(p2, p1, q2)) return true;
219. if(o4 == 0 && onSegment(p2, q1, q2)) return true;
220. return false;
221. }
222. };
223.
224. class priorityQueueComparator{
225. public:
226. struct Person {
227. int age, height;
228. };
229.
230. struct customCompare{
231. bool operator()(Person p, Person q){
232. return p.age<q.age;
233. }
234. };
235. priority_queue<Person, vector<Person>, customCompare> pq;
236. };
237.
238. class operatorOverloading{
239. struct Person{
240. int age, height;
241. Person(int _age, int _height){
242. age = _age;
243. height = _height;
244. }
245. bool operator < (const Person &other){
246. return age < other.age;
247. }
248. };
249. };
You might also like
Artificial Intelligence Research Paper Topics
PDF
No ratings yet
Artificial Intelligence Research Paper Topics
6 pages
Ads Lab Manual
PDF
No ratings yet
Ads Lab Manual
124 pages
Leetcode CPP PDF
PDF
No ratings yet
Leetcode CPP PDF
262 pages
RPA Introduction
PDF
No ratings yet
RPA Introduction
15 pages
DSA Ashish Aaher 01
PDF
No ratings yet
DSA Ashish Aaher 01
108 pages
Setprecision
PDF
No ratings yet
Setprecision
9 pages
IEEE Xplore Reference Download 2025.3.12.15.58.20
PDF
No ratings yet
IEEE Xplore Reference Download 2025.3.12.15.58.20
2 pages
Object Oriented Programming With C++
PDF
No ratings yet
Object Oriented Programming With C++
24 pages
C Program
PDF
No ratings yet
C Program
8 pages
Document 22
PDF
No ratings yet
Document 22
62 pages
ADSA File
PDF
No ratings yet
ADSA File
28 pages
Rest API Interview Questions
PDF
No ratings yet
Rest API Interview Questions
5 pages
DAA Practical Quick Revision Kit
PDF
No ratings yet
DAA Practical Quick Revision Kit
5 pages
DSA Lab Projects Group One
PDF
No ratings yet
DSA Lab Projects Group One
4 pages
All STL CPP
PDF
No ratings yet
All STL CPP
3 pages
STL Data Structures
PDF
No ratings yet
STL Data Structures
17 pages
En Leaflet Compact CC Defonline 202205
PDF
No ratings yet
En Leaflet Compact CC Defonline 202205
2 pages
CORE - 14 - Algorithm Design Techiniques
PDF
No ratings yet
CORE - 14 - Algorithm Design Techiniques
14 pages
Dsa Practical Codes
PDF
No ratings yet
Dsa Practical Codes
39 pages
P Ques6 Binary Search Tree
PDF
No ratings yet
P Ques6 Binary Search Tree
4 pages
Craiyon - Your FREE AI Image Generator Tool Create AI Art!
PDF
No ratings yet
Craiyon - Your FREE AI Image Generator Tool Create AI Art!
1 page
Mock Que
PDF
No ratings yet
Mock Que
2 pages
String
PDF
No ratings yet
String
4 pages
0.1 Top 100 Dsa Interview Questions
PDF
No ratings yet
0.1 Top 100 Dsa Interview Questions
3 pages
Shaders Excerpt
PDF
No ratings yet
Shaders Excerpt
51 pages
Ads All Codes
PDF
No ratings yet
Ads All Codes
42 pages
Modules and Ports
PDF
No ratings yet
Modules and Ports
20 pages
Google - Testinises.professional Cloud Architect - Dumps.2024 Jul 16.by - Burgess.119q.vce
PDF
No ratings yet
Google - Testinises.professional Cloud Architect - Dumps.2024 Jul 16.by - Burgess.119q.vce
13 pages
DSAmidterm
PDF
No ratings yet
DSAmidterm
14 pages
Notes9 - Class - 10 - Data Visualization Using MatPlotlib Notes
PDF
No ratings yet
Notes9 - Class - 10 - Data Visualization Using MatPlotlib Notes
5 pages
Anubhav Kaushik 22102035 Dsa Assignment 5
PDF
No ratings yet
Anubhav Kaushik 22102035 Dsa Assignment 5
9 pages
CTDL và GT Danh sách liên kết
PDF
No ratings yet
CTDL và GT Danh sách liên kết
6 pages
Black White Minimalist CV Resume
PDF
No ratings yet
Black White Minimalist CV Resume
1 page
Design and Analysis of Algorithms Lab
PDF
No ratings yet
Design and Analysis of Algorithms Lab
24 pages
Dsa Ans
PDF
No ratings yet
Dsa Ans
9 pages
MEMORIZACIÓN Métodos para Piano Recopilación de Chuan C. Chuang 1
PDF
No ratings yet
MEMORIZACIÓN Métodos para Piano Recopilación de Chuan C. Chuang 1
22 pages
Aashish ADS
PDF
No ratings yet
Aashish ADS
23 pages
AashishADS 2
PDF
No ratings yet
AashishADS 2
23 pages
Eti MP
PDF
No ratings yet
Eti MP
18 pages
Array List
PDF
No ratings yet
Array List
4 pages
PU BruteForceTroop
PDF
No ratings yet
PU BruteForceTroop
16 pages
Tally Prime Digital e Bookk
PDF
No ratings yet
Tally Prime Digital e Bookk
79 pages
ICPC Final
PDF
No ratings yet
ICPC Final
25 pages
Data Structures and Algorithms Algorithms in C++: Jordi Petit Salvador Roura Albert Atserias
PDF
No ratings yet
Data Structures and Algorithms Algorithms in C++: Jordi Petit Salvador Roura Albert Atserias
69 pages
Competitive Programming Notebook: Joao Carreira 2010
PDF
No ratings yet
Competitive Programming Notebook: Joao Carreira 2010
21 pages
Module 6 Analytics-Making Sense of Data
PDF
No ratings yet
Module 6 Analytics-Making Sense of Data
9 pages
Replacement For MAX803-809-810 3 Pin Microprocessor Reset Circuits
PDF
No ratings yet
Replacement For MAX803-809-810 3 Pin Microprocessor Reset Circuits
2 pages
SIP5 - 7SA SD 82 84 86 7SL 82 86 SJ 86 - V08.40 - Manual - C010 E - en
PDF
0% (1)
SIP5 - 7SA SD 82 84 86 7SL 82 86 SJ 86 - V08.40 - Manual - C010 E - en
2,200 pages
Data Structure and Algorithm
PDF
No ratings yet
Data Structure and Algorithm
18 pages
Lab Fat Daa
PDF
No ratings yet
Lab Fat Daa
24 pages
OSaged
PDF
No ratings yet
OSaged
9 pages
Icct Colleges Foundation, Inc
PDF
No ratings yet
Icct Colleges Foundation, Inc
7 pages
Empty 2. Size 3. Top 4. Push 5. Pop 6. Swap Mypqueue1.swap (Mypqueue2) 7. For Min Heap
PDF
No ratings yet
Empty 2. Size 3. Top 4. Push 5. Pop 6. Swap Mypqueue1.swap (Mypqueue2) 7. For Min Heap
3 pages
Complex Problen ADSA
PDF
No ratings yet
Complex Problen ADSA
16 pages
Templates
PDF
No ratings yet
Templates
7 pages
Assignment 1
PDF
No ratings yet
Assignment 1
9 pages
June 2023 (v1) QP - Paper 1 CAIE Computer Science IGCSE
PDF
No ratings yet
June 2023 (v1) QP - Paper 1 CAIE Computer Science IGCSE
12 pages
Allprogs
PDF
No ratings yet
Allprogs
17 pages
Drfgdfdgdfffgdss
PDF
No ratings yet
Drfgdfdgdfffgdss
15 pages
IDPC Template
PDF
No ratings yet
IDPC Template
5 pages
Sick Analogue Sensor Accuracy
PDF
No ratings yet
Sick Analogue Sensor Accuracy
4 pages
ADS Lab Manual PDF
PDF
No ratings yet
ADS Lab Manual PDF
54 pages
Leetcode CPP
PDF
No ratings yet
Leetcode CPP
262 pages
Output
PDF
No ratings yet
Output
8 pages
The Effects of Social Media in The Academic Performance of The Grade 12 Students of Limay Senior High School
PDF
No ratings yet
The Effects of Social Media in The Academic Performance of The Grade 12 Students of Limay Senior High School
4 pages
Security Vendor Questionnaire
PDF
No ratings yet
Security Vendor Questionnaire
2 pages
Sort
PDF
No ratings yet
Sort
7 pages
LAB1
PDF
No ratings yet
LAB1
12 pages
Ilovepdf Merged
PDF
No ratings yet
Ilovepdf Merged
46 pages
Icpc Handbook - Gareebcoders: Index
PDF
No ratings yet
Icpc Handbook - Gareebcoders: Index
18 pages
PLACEMENT PRACTICE 10-12-2024, Himanshu
PDF
No ratings yet
PLACEMENT PRACTICE 10-12-2024, Himanshu
17 pages
21bcs8137 Naman It Day8
PDF
No ratings yet
21bcs8137 Naman It Day8
8 pages
p89v51 Semi
PDF
No ratings yet
p89v51 Semi
3 pages
数据结构例题
PDF
No ratings yet
数据结构例题
6 pages
Exam Booklet
PDF
No ratings yet
Exam Booklet
5 pages
3.scanning Network
PDF
No ratings yet
3.scanning Network
25 pages
Module #1 WORKSHOP 1 - ICT - C1
PDF
No ratings yet
Module #1 WORKSHOP 1 - ICT - C1
7 pages
C Prog
PDF
No ratings yet
C Prog
8 pages
H802SCUN Board Datasheet
PDF
No ratings yet
H802SCUN Board Datasheet
1 page
CSE2012 Lab Assignment 1
PDF
No ratings yet
CSE2012 Lab Assignment 1
22 pages
C++ Guides
PDF
No ratings yet
C++ Guides
6 pages
Test 2: CPS 100: Owen Astrachan November 15, 2000
PDF
No ratings yet
Test 2: CPS 100: Owen Astrachan November 15, 2000
9 pages
Leetcode CPP
PDF
No ratings yet
Leetcode CPP
262 pages
Model Welds in Drawings Tekla
PDF
No ratings yet
Model Welds in Drawings Tekla
3 pages
The Ultimate Multitrack Playback Set Up For Ableton Live
PDF
No ratings yet
The Ultimate Multitrack Playback Set Up For Ableton Live
2 pages
No Ph.D. Game Design With Three.js
From Everand
No Ph.D. Game Design With Three.js
Nikiforos Kontopoulos
No ratings yet
Advanced C Concepts and Programming: First Edition
From Everand
Advanced C Concepts and Programming: First Edition
Gayatri
3/5 (1)
150+ C Pattern Programs
From Everand
150+ C Pattern Programs
Hernando Abella
No ratings yet
Computer Engineering Laboratory Solution Primer
From Everand
Computer Engineering Laboratory Solution Primer
Karan Bhandari
No ratings yet