Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Loading...
User Settings
close menu
Welcome to Scribd!
Upload
Read for free
FAQ and support
Language (EN)
Sign in
0 ratings
0% found this document useful (0 votes)
6 views
Interview Codes
Uploaded by
babynamenestlings
interview preparation coding set
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF, TXT or read online from Scribd
Download
Save
Save Interview Codes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Interview Codes
Uploaded by
babynamenestlings
0 ratings
0% found this document useful (0 votes)
6 views
5 pages
Document Information
click to expand document information
interview preparation coding set
Copyright
© © All Rights Reserved
Available Formats
PDF, TXT or read online from Scribd
Share this document
Share or Embed Document
Sharing Options
Share on Facebook, opens a new window
Facebook
Share on Twitter, opens a new window
Twitter
Share on LinkedIn, opens a new window
LinkedIn
Share with Email, opens mail client
Email
Copy link
Copy link
Did you find this document useful?
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Is this content inappropriate?
Report
interview preparation coding set
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF, TXT or read online from Scribd
Download now
Download as pdf or txt
Save
Save Interview Codes For Later
0 ratings
0% found this document useful (0 votes)
6 views
5 pages
Interview Codes
Uploaded by
babynamenestlings
interview preparation coding set
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF, TXT or read online from Scribd
Save
Save Interview Codes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download as pdf or txt
Jump to Page
You are on page 1
of 5
Search inside document
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
Activity Template - Project Charter
Document
3 pages
Activity Template - Project Charter
abhilash
88% (8)
Kilo Source Code Listing Scribd
Document
18 pages
Kilo Source Code Listing Scribd
unni2003
No ratings yet
Neha Das Assign2
Document
10 pages
Neha Das Assign2
Neha Das
No ratings yet
CTDL và GT Danh sách liên kết
Document
6 pages
CTDL và GT Danh sách liên kết
tranhuu181924
No ratings yet
NTC File
Document
49 pages
NTC File
SOUMY PRAJAPATI
No ratings yet
Lab 52
Document
4 pages
Lab 52
ahmadpsh305
No ratings yet
Analysis Algo
Document
41 pages
Analysis Algo
Sweekriti Singh
No ratings yet
Project Foodie
Document
42 pages
Project Foodie
baisoyavaibhav2000
No ratings yet
DAA Final
Document
43 pages
DAA Final
Sunny Varshney
No ratings yet
Final_CPP_Programs_with_Outputs
Document
9 pages
Final_CPP_Programs_with_Outputs
abhishekgupta1271999
No ratings yet
DAA FILE Taran
Document
33 pages
DAA FILE Taran
The James
No ratings yet
CN World Cup Complete Solution
Document
28 pages
CN World Cup Complete Solution
samanta.sourav2000
No ratings yet
For Random Numbers: Randomgenerator
Document
3 pages
For Random Numbers: Randomgenerator
sara amer
No ratings yet
Union Int Int Union: Return
Document
4 pages
Union Int Int Union: Return
Good Win Rock
No ratings yet
Doubly Linked List
Document
10 pages
Doubly Linked List
AKASH KOTNALA
No ratings yet
Estrutura de Dados - Prova 2
Document
21 pages
Estrutura de Dados - Prova 2
theo.bortoletto
No ratings yet
Design and Analysis of Algorithms Lab
Document
24 pages
Design and Analysis of Algorithms Lab
901Anirudha Shivarkar
No ratings yet
Merge2 2
Document
5 pages
Merge2 2
ahmadpsh305
No ratings yet
Merge
Document
8 pages
Merge
ahmadpsh305
No ratings yet
RITIK DESWAL (19CSE043) DAA PRACTICAL FILE - Ruchi CSE
Document
32 pages
RITIK DESWAL (19CSE043) DAA PRACTICAL FILE - Ruchi CSE
Ankit bahuguna
No ratings yet
Reverse Ömer Faruk Tunç
Document
3 pages
Reverse Ömer Faruk Tunç
Ömer Faruk TUNÇ
No ratings yet
Solutions TPEC
Document
27 pages
Solutions TPEC
vvce21cse0148
No ratings yet
Ada Lab File - Deepak Yadav
Document
25 pages
Ada Lab File - Deepak Yadav
Deepak
No ratings yet
Lab 7
Document
5 pages
Lab 7
ahmadpsh305
No ratings yet
Adt Queue
Document
14 pages
Adt Queue
Yunyttha Leztary
No ratings yet
Long Long Const Double Const Double Struct Double Double Double Void Void Double Double Double
Document
4 pages
Long Long Const Double Const Double Struct Double Double Double Void Void Double Double Double
سارة طليمات
No ratings yet
Scode Bab 2
Document
7 pages
Scode Bab 2
nadhirah
No ratings yet
Daa PR
Document
15 pages
Daa PR
abhikicopy
No ratings yet
Assignment - 1
Document
35 pages
Assignment - 1
Ayush Gupta
No ratings yet
ICPC Codes
Document
13 pages
ICPC Codes
hby7616
No ratings yet
AADS_pracfile
Document
27 pages
AADS_pracfile
beinggord02
No ratings yet
Dsa Extra Program
Document
25 pages
Dsa Extra Program
Ansh Balgotra
No ratings yet
DSA Stack and Queues + Extras
Document
64 pages
DSA Stack and Queues + Extras
vedant bhatnagar
No ratings yet
DAA_9-12
Document
10 pages
DAA_9-12
shivadubey2002
No ratings yet
Design and Analysis of Algorithm
Document
15 pages
Design and Analysis of Algorithm
swathisaipragnya
No ratings yet
DAA Elab 1
Document
127 pages
DAA Elab 1
anant33331
No ratings yet
Assembly Line Scheduling and Optimal Path
Document
57 pages
Assembly Line Scheduling and Optimal Path
Aditya Thakre
No ratings yet
ADVANCEsat
Document
51 pages
ADVANCEsat
kdasari3
No ratings yet
DS Codes
Document
8 pages
DS Codes
yash rawat (RA1911031010029)
No ratings yet
CSC161 Exam 1 Listings
Document
5 pages
CSC161 Exam 1 Listings
Blake Mills
No ratings yet
Analysis and Design of Algorithms Lab File: Submitted by
Document
20 pages
Analysis and Design of Algorithms Lab File: Submitted by
vaibhav30388
No ratings yet
SCP4
Document
18 pages
SCP4
alexserban150
No ratings yet
Rishi Lab-10
Document
11 pages
Rishi Lab-10
mrudulshah24
No ratings yet
Lab 5
Document
6 pages
Lab 5
ahmadpsh305
No ratings yet
Shell
Document
6 pages
Shell
api-744403598
No ratings yet
Program11
Document
9 pages
Program11
Johnny GAMER
No ratings yet
Dsa Answers Elab 1
Document
954 pages
Dsa Answers Elab 1
biyiti9701
No ratings yet
Dsa Megalist 2
Document
1,182 pages
Dsa Megalist 2
E.ANANDAPERUMAL
100% (1)
samsung
Document
3 pages
samsung
resign please
No ratings yet
Lab Manual MCSE 101
Document
35 pages
Lab Manual MCSE 101
Juan Jackson
No ratings yet
Advanced Data Structures
Document
29 pages
Advanced Data Structures
sirishaksnlp
No ratings yet
BST Operations
Document
5 pages
BST Operations
Komal Rathod
No ratings yet
ALgo Lab Codes
Document
26 pages
ALgo Lab Codes
BIPRONIL GHOSH
No ratings yet
Progi
Document
14 pages
Progi
irakli meparishvili
No ratings yet
Data Algorithm Analysis Lab File
Document
27 pages
Data Algorithm Analysis Lab File
imabhishek5677
No ratings yet
#Include: Using Namespace
Document
14 pages
#Include: Using Namespace
Andreea Stewert
No ratings yet
Adaspam
Document
15 pages
Adaspam
poori.2819.hapo
No ratings yet
C Programs Final
Document
37 pages
C Programs Final
SanJeev Dani PeDrosa
No ratings yet
SplitPDFFile 90 To 108
Document
19 pages
SplitPDFFile 90 To 108
Technical Gaming
No ratings yet
Bubble Sort
Document
20 pages
Bubble Sort
Yo boi Jogindar
No ratings yet
150+ C Pattern Programs
From Everand
150+ C Pattern Programs
Hernando Abella
No ratings yet
Automation in Production: B.E. (Mechanical Engineering) Eighth Semester (C.B.S.)
Document
4 pages
Automation in Production: B.E. (Mechanical Engineering) Eighth Semester (C.B.S.)
Sufiyan Rehman
No ratings yet
Apc200 Ecm
Document
54 pages
Apc200 Ecm
Falcon Man
No ratings yet
Activity-Sheet-Math5-Q3-Week 6
Document
2 pages
Activity-Sheet-Math5-Q3-Week 6
Edhen Joy Perolina
No ratings yet
Furuno Ecdis Trainee Course Manual Version 4.0
Document
46 pages
Furuno Ecdis Trainee Course Manual Version 4.0
Kevin Linn
No ratings yet
Video Game Hall of Fame Bios
Document
2 pages
Video Game Hall of Fame Bios
News10NBC
No ratings yet
Alcatel Lacp Configuration
Document
4 pages
Alcatel Lacp Configuration
hendrisusanto.tik
No ratings yet
Causative Constructions: I'll Get Him To Lend Us The Money. ( I'll Persuade Him )
Document
2 pages
Causative Constructions: I'll Get Him To Lend Us The Money. ( I'll Persuade Him )
Nicole D, Hale
No ratings yet
HFP Ap-4: Analogue Fire Alarm Control Panel
Document
1 page
HFP Ap-4: Analogue Fire Alarm Control Panel
Joe Bou Nader
No ratings yet
Human Language Understanding and Reasoning
Document
12 pages
Human Language Understanding and Reasoning
Ieong Nicole
No ratings yet
Advanced Abaqus FEA For SolidWorks Designers and Engineers
Document
3 pages
Advanced Abaqus FEA For SolidWorks Designers and Engineers
Senad Balic
No ratings yet
Chapter 2 Major Board (Parts) of Each System: Rev.E
Document
9 pages
Chapter 2 Major Board (Parts) of Each System: Rev.E
Mario Rodríguez
No ratings yet
MC Unit 5
Document
22 pages
MC Unit 5
4309 Surya .s
No ratings yet
Ultra9030HF-Manual ENG 110922
Document
29 pages
Ultra9030HF-Manual ENG 110922
JohnnyD
No ratings yet
C Notes For CP
Document
6 pages
C Notes For CP
Radhika sharma
No ratings yet
Las Ict Csa 9 Q3 Week 1
Document
10 pages
Las Ict Csa 9 Q3 Week 1
Karell Ann
No ratings yet
Mitsubishi Controler Model
Document
69 pages
Mitsubishi Controler Model
Huấn Giáp
No ratings yet
Unit 3 Lesson 1
Document
32 pages
Unit 3 Lesson 1
Angela Donahey
No ratings yet
Eaton Fire Addressable Control Panel cf3000 Datasheet 0719 PDF
Document
2 pages
Eaton Fire Addressable Control Panel cf3000 Datasheet 0719 PDF
mjay90
No ratings yet
Item 1 & 2
Document
5 pages
Item 1 & 2
Allen Wong
No ratings yet
InPlant Training
Document
24 pages
InPlant Training
Swastik gupta
No ratings yet
Prosafe PDF
Document
460 pages
Prosafe PDF
Akash Joseph
No ratings yet
DP100
Document
8 pages
DP100
srimounika srinivas
No ratings yet
Spreading Guide
Document
11 pages
Spreading Guide
urexalg Algéria
No ratings yet
Philips Zenition 50 C Arm
Document
2 pages
Philips Zenition 50 C Arm
Larissa Braga
No ratings yet
Essenta DR Compact Installation
Document
20 pages
Essenta DR Compact Installation
Bassam Ghazi
No ratings yet
OCR-free Document Understanding Transformer
Document
21 pages
OCR-free Document Understanding Transformer
Baby Dream
No ratings yet
5) Public Relations Budget Template
Document
11 pages
5) Public Relations Budget Template
Bhaktivedanta Hospital
No ratings yet
General Ability AE AEE Civil Engineering Handwritten Notes PDF
Document
121 pages
General Ability AE AEE Civil Engineering Handwritten Notes PDF
Entertainment SNEHANSH ESA
No ratings yet
RDR Goty Ps3 Essentials Manual Eng
Document
15 pages
RDR Goty Ps3 Essentials Manual Eng
elisah.isayah
No ratings yet