Coding Practice
Sunday, 4 April 2021
Write Ahead Logging
Saturday, 17 October 2020
Diameter of a tree
Problem: Given edges for a tree find the diameter of the tree or the longest path in the tree.
Sample Input:
4
5 1
1 3
1 2
2 4
Representation of tree: Tree can be represented in multiple ways,
1. If we simplify the problem and say it is a binary tree we can represent it as array where a[i]-> left is a[2*i] and a[i]->right is a[2*i+1].
2. One other way to represent it is by using parent array: parrent[i] = j if there is an edge j->i but the tree needs to be directed in this case
3. We can have a struct/class Node which has pointers to left and right
Node {
int val,
Node* left,
Node* right
}
To calculate the diameter of a tree we have to pick a root and do dfs/bfs to find the left node with maximum distance and find the farthest node from it.
Tuesday, 25 August 2020
Sorting and Searching [CSES] [Day-2]
Movie Festival
Sunday, 23 August 2020
Sorting and Searching [CSES] [DAY-1]
Distinct Number
Ferris Wheel
Concert Ticket
Wednesday, 19 August 2020
Introductory Problems [CSES]
Weird Algorithm
Missing Numbers
Create Strings 1:
Apple Division
for (int i = 0; i < 1 << n; i++) {
// new combination
for (int j = 0; j <= n; j++) {
if (1 << j & i) {
// included in current combination
}
}
}Write Ahead Logging
In applications that needs to run continuously, ability to recover is key when a component goes down. If the component is transactional in n...
-
Weird Algorithm This is a simulation-based problem, we have to multiply the number with 3 and add on...
-
Distinct Number Given n integers find number of disctinct integers among them. Constraint : 'n <= 2 * 10^5'. Tried by maintai...
-
In applications that needs to run continuously, ability to recover is key when a component goes down. If the component is transactional in n...