What’s up fellow nerds
Hope you’re having a terrific day. Here’s the interview problem and industry news for the day!
Daily Interview Problem
You’re given an N x N matrix
where some of the items in the matrix are 0. If any of the items are 0, then set the item’s entire row and column to 0. Items that are not 0 will be represented by an integer.
Input - [
[1,2,3,4],
[5,0,7,8],
[6,1,1,2],
[2,3,4,0]
]
Output - [
[1,0,3,4],
[5,0,7,8],
[6,0,1,2],
[0,0,0,0]
]
Here’s a REPL with unit tests so you can code it out yourself!
Once you start editing the code then REPL will automatically fork it for you!
I’ll send you the solution to this question tomorrow!
Industry News
Oracle in talks to acquire TikTok - Oracle has entered the race to acquire TikTok, the extremely popular Chinese-owned short video app that appeals to teenagers across the world. The acquisition is an amazing example of Oracle playing the long game to show teenagers the benefits of Oracle Cloud Infrastructure versus AWS or Azure. Just kidding. No clue why they want to buy TikTok. Read More.
Amazon expanding corporate offices in 6 major cities - Obviously, Amazon is doing extremely well right now (for those of you who work at Amazon, congrats on your RSUs lol). Amazon is adding 3500 corporate jobs across 6 major cities, including 2000 jobs in NYC. The NYC office will be on Fifth Avenue in the historic building that once housed the Lord & Taylor Flagship store. Read More
Nvidia expanding Cloud Gaming Service to ChromeOS - Cloud Gaming is super hot right now, and there’s little question why. Fortnite showed the massive interest in the gaming space, and Google took the plunge with Stadia. Games are streamed using WebRTC, so you don’t need to download any dedicated app, it just works in your browser. Cloud gaming services like Stadia or GeForce Now (Nvidia’s service) have yet to gain wide adoption on mobile, but GeForce Now on ChromeOS is a promising sign. Read More.
Yesterday’s Solution
As a refresher, here’s yesterday’s problem.
You are given n non-negative integers that represent a series of blocks. The integers represent the height of a block. The width of each block is 1. The blocks are placed one after another. If it rains over the blocks compute how much water the blocks will trap.
Example with input [0,1,0,2,1,0,1,3,2,1,2,1]
Input:
[0,1,0,2,1,0,1,3,2,1,2,1]
Output:
6
Solution
So, just for this question, I’m not going to write out an explanation.
I’ve found this amazing YouTube video that goes through all the solutions for this question and shows you how to solve the problem intuitively.
It’s three parts in total, but I think you should definitely watch all 3 parts, since you’ll learn a lot more than just how to solve the problem. I have no idea who the creator of those videos is, but he did a hell of a job.
You can view my python code for this problem (with test cases) here!
The optimal solution runs in O(n)
time and takes O(1)
extra space.