Programming IN C
Lecture 1: Part 1 |
|
Lecture 1: Part 2 |
|
Lecture 1: Part 3 |
|
Lecture 1: Part 4 |
|
Lecture 1: Part 5 |
|
Lecture 2: Part 1 |
|
Lecture 2: Part 2 |
|
Lecture 3: Part 1 |
|
Lecture 3: Part 2 |
|
Lecture 3: Part 3 |
|
Lecture 4 |
|
Lecture 5 |
|
Lecture 6 |
|
Lecture 7: Part 1 |
|
Lecture 7: Part 2 |
|
Lecture 8 |
|
Lecture 9 |
|
Lecture 10 |
|
Lecture 11 |
|
Lecture 12 |
|
Lecture 13 |
|
Lecture 14 |
|
Lecture 15 |
|
Lecture 16 |
|
Lecture 17 |
|
Lecture 18 |
|
Lecture 19 |
|
Lecture 20 |
|
Revision Lecture 1 |
|
Test Paper
Question 1: (10 marks)
Design a class to efficiently find the Kth largest element in a stream of numbers. Provide the constructor and the add(int num) function. Explain the time complexity of your implementation.
Question 2: (12 marks)
Given a sorted number array [2, 4, 6, 8, 10, 12, 14] and integers ‘K’ and ‘X’ (let's say K=3, X=7), find ‘K’ closest numbers to ‘X’ in the array. Return the numbers in sorted order. Explain the efficiency of your solution.
Question 3: (8 marks)
You are given the head of a linked list and a key. Write a function to delete the node that contains the given key. Explain the time and space complexity of your solution.
Question 4: (15 marks)
Given a linked list with arbitrary pointers, write code to make a deep copy of the given linked list. Ensure that any operations on the original list do not affect the copied list. Explain the efficiency of your solution.
Question 5: (10 marks)
Given the root node of a binary tree, swap the ‘left’ and ‘right’ children for each node. Provide the modified tree after swapping. Explain the time complexity of your algorithm.
Question 6: (12 marks)
Given a binary tree and a number ‘S’, find all paths from root-to-leaf such that the sum of all the node values of each path equals ‘S’. Discuss the efficiency of your solution.
Question 7: (8 marks)
Given a string, find the length of the longest substring with no more than K distinct characters. Provide an example and analyze the time complexity of your solution.
Question 8: (10 marks)
Given a string, determine if its letters can be rearranged in such a way that no two same characters come next to each other. Explain the approach and its time complexity.
Question 9: (10 marks)
Given a set of positive numbers, find if we can partition it into two subsets such that the sum of elements in both subsets is equal. Discuss the efficiency of your solution.
Question 10: (8 marks)
Given an input string, determine if it makes a valid number or not. For simplicity, assume that white spaces are not present in the input. Explain the conditions for validity and your implementation.
Question 11: (8 marks)
Print all braces combinations for a given value ‘N’ so that they are balanced. Provide examples and analyze the time complexity of your solution.
Question 12: (15 marks)
There are ‘N’ tasks, labeled from ‘0’ to ‘N-1’. Each task can have some prerequisite tasks. Given the number of tasks and a list of prerequisite pairs, find out if it is possible to schedule all the tasks. Discuss the efficiency of your solution.
Question 13: (15 marks)
Implement a Least Recently Used (LRU) cache with the policy to evict the least recently used items first when the cache is full. Explain the data structures used and analyze the time complexity of cache operations.
Question 14: (10 marks)
Given a sorted array of integers, return the low and high index of the given key. Return -1 if not found. The array length can be in the millions with many duplicates. Discuss the efficiency of your solution.
Question 15: (10 marks)
You are given an array (list) of interval pairs with start and end timestamps. The input array is sorted by starting timestamps. Merge overlapping intervals and return the output array. Provide examples and analyze the time complexity of your solution.
Design a class to efficiently find the Kth largest element in a stream of numbers. Provide the constructor and the add(int num) function. Explain the time complexity of your implementation.
Question 2: (12 marks)
Given a sorted number array [2, 4, 6, 8, 10, 12, 14] and integers ‘K’ and ‘X’ (let's say K=3, X=7), find ‘K’ closest numbers to ‘X’ in the array. Return the numbers in sorted order. Explain the efficiency of your solution.
Question 3: (8 marks)
You are given the head of a linked list and a key. Write a function to delete the node that contains the given key. Explain the time and space complexity of your solution.
Question 4: (15 marks)
Given a linked list with arbitrary pointers, write code to make a deep copy of the given linked list. Ensure that any operations on the original list do not affect the copied list. Explain the efficiency of your solution.
Question 5: (10 marks)
Given the root node of a binary tree, swap the ‘left’ and ‘right’ children for each node. Provide the modified tree after swapping. Explain the time complexity of your algorithm.
Question 6: (12 marks)
Given a binary tree and a number ‘S’, find all paths from root-to-leaf such that the sum of all the node values of each path equals ‘S’. Discuss the efficiency of your solution.
Question 7: (8 marks)
Given a string, find the length of the longest substring with no more than K distinct characters. Provide an example and analyze the time complexity of your solution.
Question 8: (10 marks)
Given a string, determine if its letters can be rearranged in such a way that no two same characters come next to each other. Explain the approach and its time complexity.
Question 9: (10 marks)
Given a set of positive numbers, find if we can partition it into two subsets such that the sum of elements in both subsets is equal. Discuss the efficiency of your solution.
Question 10: (8 marks)
Given an input string, determine if it makes a valid number or not. For simplicity, assume that white spaces are not present in the input. Explain the conditions for validity and your implementation.
Question 11: (8 marks)
Print all braces combinations for a given value ‘N’ so that they are balanced. Provide examples and analyze the time complexity of your solution.
Question 12: (15 marks)
There are ‘N’ tasks, labeled from ‘0’ to ‘N-1’. Each task can have some prerequisite tasks. Given the number of tasks and a list of prerequisite pairs, find out if it is possible to schedule all the tasks. Discuss the efficiency of your solution.
Question 13: (15 marks)
Implement a Least Recently Used (LRU) cache with the policy to evict the least recently used items first when the cache is full. Explain the data structures used and analyze the time complexity of cache operations.
Question 14: (10 marks)
Given a sorted array of integers, return the low and high index of the given key. Return -1 if not found. The array length can be in the millions with many duplicates. Discuss the efficiency of your solution.
Question 15: (10 marks)
You are given an array (list) of interval pairs with start and end timestamps. The input array is sorted by starting timestamps. Merge overlapping intervals and return the output array. Provide examples and analyze the time complexity of your solution.