- InstaByte
- Posts
- π₯ Amazon asked this math problem
π₯ Amazon asked this math problem
ALSO: How to design TinyURL
Welcome back, Interview Masters!
Todayβs coding challenge was asked by Amazon 18 times. Letβs see if you can solve it.
Today, weβll cover:
Rotate Image problem
How to design TinyURL
Read time: under 3 minutes
CODING CHALLENGE
Rotate Image
You are given an n x n
2D matrix
representing an image, rotate the image by 90 degrees (clockwise).
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Example 1:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]
Solve the problem here before reading the solution.
WE NEED YOUR HELP
Many people are not getting our emails because they are going to the βspamβ folder.
Please help us by replying βokβ to this email. This will tell Gmail not to mark our emails as spam. Thank you!
SOLUTION
To solve this problem, we will follow a two-step process.
First, we will swap the element at position (i, j)
with the element at position (j, i)
. This is also called transposing a matrix.
Then, we will reverse each row.
Time complexity of this solution is O(n^2
) due to nested loop.
SYSTEM DESIGN EXPLAINED
How to design TinyURL?
Source: Ad Espresso
Let's design a service like TinyURL for shortening a long URL.
The main functional requirements are: Generating short URLs and redirecting short URLs to original long URLs.
We need a system that's highly available and handles redirects with low latency. Additionally, shortened URLs should be unpredictable and human-readable.
Weβll use a key-value database to store long URLs alongside their shortened versions. A sequencer would generate unique IDs that are then converted into alphanumeric codes using a base-58 encoding scheme for readability. Caching can improve performance by storing frequently accessed shortened URLs.
Check out this article for more details.
NEWS
This week in the tech world
Source: NBC News
Scarlett Johansson vs OpenAI: Scarlett Johansson is accusing AI company OpenAI of ripping off her voice after she declined an offer to voice GPT-4o. Johansson says the AI voice called Sky sounds suspiciously similar to her voice, but OpenAI denies it.
Tesla layoffs continue: Tesla is laying off 600 employees in California as part of a larger restructuring after a sales and stock price slump. CEO Elon Musk said the company would cut more than 10% of its global workforce.
Microsoft relocates AI staff from China: Microsoft is offering relocation to hundreds of China-based AI staff amid US-China tech tensions. The company fears China may use the technology for military purposes, and is complying with US restrictions on advanced AI technology.
India favorable for IPOs: Investment bank Peak XV says India offers a very favorable environment for firms to go public due to a strong economy, optimistic investor sentiment, and fewer regulations compared to other countries. In 2023, there were more IPOs in India than anywhere else, except mainland China.
Google 3D images in Ads: Google is shaking up search results by letting retailers use generative AI to create visual content for their ads, including 3D images and product summaries. This could push traditional text results further down the page.
SpaceX Starlink in Indonesia: Elon Musk launched SpaceX's Starlink internet service in Indonesia, aiming to bring internet connectivity to remote areas. This could be a "life-saver" according to Musk, and he hinted at further investment from his companies in Indonesia.
Microsoft's AI PCs: Microsoft is entering the race for AI-powered PCs with new machines that use Qualcomm chips. These chips promise longer battery life and the ability to run AI features without an internet connection.
BONUS
Just for laughs π
Source: Programmer Humor
YOUR FEEDBACK
What did you think of this week's email?Your feedback helps us create better emails for you! |
Until next time, take care! π
Cheers,