Skill Lab
Skill Lab
BACHELOR OF ENGINEERING
In
COMPUTER SCIENCE & ENGINEERING
Submitted by
NAME:SUSHMITHA REDDY.B
#include <map>
#include <string>
int main()
int n;
std::cin >> n;
phoneBook[name] = number;
std::string query;
if (phoneBook.find(query) != phoneBook.end())
else
return 0;
}
LINKED LIST
class Node:
self.data = data
self.next = None
class LinkedList:
def _init_(self):
self.head = None
if not self.head:
self.head = Node(data)
else:
curr = self.head
while curr.next:
curr = curr.next
curr.next = Node(data)
class Solution:
count = 0
current = head
while current:
count += 1
current = current.next
return count % 2 == 0
llist = LinkedList()
llist.append(value)
flag = Solution().isLengthEven(llist.head)
print(flag)
TRESS
SAME TREE
class Solution {
public:
// If one of them is null or values don't match, trees aren't the same
} };
BINARY SEARCH TREE
def checkBST(root):
if node is None:
return True
return False
class Solution {
public:
lookup
string word;
result << (dict.count(prefix) ? prefix : word) << " "; // Use root if found
return res;
};
STACKS AND QUEUES
VALID PARENTHESIS
class Solution {
public:
bool isValid(string s) {
stack<char> stk;
for (char c : s) {
stk.push(c);
} else {
return false;
stk.pop();
HEAPS
QHEAP1
import java.io.*;
import java.util.*;
if (queryType == 1) {
int x = sc.nextInt();
minHeap.add(x);
} else if (queryType == 2) {
int x = sc.nextInt();
if (elements.remove(x)) {
} else if (queryType == 3) {
System.out.println(minHeap.peek());
}
Top K Frequent Words
import java.util.*;
class Solution {
);
heap.offer(word);
if (heap.size() > k) {
while (!heap.isEmpty()) {
result.add(heap.poll());
}
Collections.reverse(result); // Highest frequency first
return result;
}
GRAPHS
COURSE SCHEDULE
graph[prereq].add(course);
inDegree[course]++;
if (inDegree[i] == 0) {
queue.offer(i);
// Process courses
while (!queue.isEmpty()) {
order[index++] = course;
inDegree[next]--;
if (inDegree[next] == 0) {
queue.offer(next);
}
REDUNDANT CONNECTION
int n = edges.length;
parent[i] = i;
int u = edge[0];
int v = edge[1];
// Find roots
if (pu == pv) {
return edge;
// Union
parent[pu] = pv;
return parent[x];
}
RUNTIME ANALYSIS
SEARCHING AND SORTING
RECURSION AND DP
CLIMBING STAIRS
class Solution {
if (n <= 1) return 1;
int a = 1, b = 1;
int temp = a + b;
a = b;
b = temp;
return b;
}
GREATEST COMMON DIVISOR
while (A != 0 && B != 0) {
if (A > B) {
A = A - B;
} else {
B = B - A;
int result = (A == 0) ? B : A;