I Was travelling in a cab around 4 am in Punjab and started chatting with the cabbie! He told me that he shifted to Punjab from Pakistan about 6 years back due to some family feud back home.
The conversation shifted from small talk to me asking him about his education and his plans for the future. He told me that he completed his B. Ed and was unable to complete his final Master's paper. Even without me asking him, he told me that he was too much interested in Shayari too.
I pressed him to share some of his…
About a decade ago, I was given three choices: Science, Commerce and Arts. A passive kid, I picked science. After all, it’s what everyone does.
Two years later, I found myself applying for colleges. Irritated that I had to think and choose again, I looked at the most popular options.
Wonderful. I copied it onto my application form.
I knew nothing about computers, save for Age of Empires and FIFA. With little exposure to the outside world, I had a romanticised view of ‘passion’ and ‘brilliance’. If this failed, I could always excuse myself…
Given an array of integers where the ith integer represents the price of the stock on day i, return the largest possible profit from completing one transaction (i.e. buying 1 share and selling 1 share).
Examples: Given the following prices…
// Buy on day 1 and sell on day 5 for a profit of 5 - 1 = 4. prices = [1, 2, 3, 4, 5], return 4. // Buy on day 4 and sell on day 9 for a profit of 11 - 1 = 10. prices = [4, 5, 2, 1, 6, 10, 4, 9, 11], return 10…
Let’s talk about a classical computer science algorithm and how it can help you avoid getting burned or your jaws mutilated from teeth chattering on a cold morning. It can also help you quickly find words in a dictionary (if you still have one lying around), and solve many other daily life issues with minimal effort.
We’ll use searching a word in a dictionary as an example. Searches often have a “search space”, which are the confinements of where our answer could be. At the beginning, the whole dictionary is our “search space”. Our aim is to keep reducing this…
My friend was drawing on the board while I looked on. We were in different teams, each assigned a project. His program currently took 5 hours to execute. The requirement stated one hour. As the ‘algorithm enthusiast’, I was called for help.
The program was to find the friends of all users in a social network. After explaining the use-case, my friend showed me his approach. I was very determined to find an optimization, hence I did. Immediately.
“An adjacency matrix?! No, use an adjacency list. The execution time will reduce in your case to O(N). Or you…
Imagine you’re the engineer responsible for building Reddit from the ground up. Walk me through how you would design the system to support the following functionality:
Think about the core components that you’ll need, and then dive deeper into them. What kind of database would you…
Sum Root to Leaf Numbers is an interesting problem from LeetCode. The problem is of medium difficulty and is about binary trees. This post is an explained solution to the problem.
I assume that you’re familiar with Python and the concept of binary trees. If you’re not, you can read this article to get started.
A man starts from the north-west (top-left) corner of the land and begins walking towards the center of it, in a spiral manner. As the man moves, he keeps track of the number of trees growing on each block of land and records the counts on his journal until he reaches his destination. This list of numbers is the key to unlock treasures hidden there.
You need to be faster than him. Satellite imagery has already provided you the count of trees on each block of land. …
You can assume there will be exactly 1 solution. Each element in the array can only be used once.
Array of integers is [2, 7, 9, -2].
The pair that sums up to 0 is (2, -2).
A list of numbers, separated by space.
2 7 9 -2
2 numbers from the array that sum up to 0.
We will sort the 2 numbers for you so that you can easily compare with our expected output.
You’re given a list of integers and a sum, S.
Array: 1 5 3 4 3
Insert, in front of each number, 1 of the 2 symbols,
-, so that the resulting sum adds up to S.
Write a function that counts all such possibilities.
In the example above, there are 3:
+1 +5 +3 -4 +3
-1 +5 +3 +4 -3
-1 +5 -3 +4 +3
Input: S followed by the list of integers.
Output: The number of possibilities where the sum adds up to S.
1 5 3 4 3…
Software Engineer @Vedantu, Former Intern @Hackerrank, GSoC @Wikimedia, Former Intern @Vedantu, Codeforces(Expert)