Will The DVD Logo Hit The Corner? - Efficiency Version
Description:
Will The DVD Logo Hit The Corner
You've probably seen the meme where people want the DVD logo to hit the corner. But it won't always hit it. When will it?
To simplify the problem, instead of a rectangular logo, it's a singular point on a graph. If at any point it hits the corners of a rectangular grid, it counts as "hitting the corner"
The logo will only move in 45° angles, changing direction similarly to the gif above.
Given the size of the "TV screen", the starting position of the "logo", and its direction, determine if it will hit the corner or not.
Input
The parameters are:
- w and h: The size of the screen (positive integers)
- x and y: The position of the logo (non negative integers), bottom left is (0, 0)
- d: The direction the logo will initially go in ("NE", "SE", "SW", or "NW")
- All inputs are valid
Output
- True if it will hit the corner (at any point)
- False if it will not hit the corner
- If it starts in a corner, that counts as a "hit"
Efficiency
Efficiency is a must. You must be able to complete inputs up to w or h being 1e30 without timing out.
Hint: Don't just simulate the entire process, find a smarter solution ;)
If the perfect algorithm is found, it can be completed in under 10ms, with no significant increase in time from small to huge numbers.
Examples
w = 12, h = 8, x = 5, y = 3, d = "NE" --> False

w = 12, h = 8, x = 5, y = 3, d = "SE" --> True

Have fun!
Similar Kata:
Stats:
Created | Mar 6, 2024 |
Published | Mar 7, 2024 |
Warriors Trained | 337 |
Total Skips | 8 |
Total Code Submissions | 1538 |
Total Times Completed | 43 |
Python Completions | 33 |
JavaScript Completions | 11 |
C# Completions | 8 |
Total Stars | 19 |
% of votes with a positive feedback rating | 92% of 12 |
Total "Very Satisfied" Votes | 10 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |