If we did hour hand minus minute hand, we'd get -75 degrees-whereas we actually want 75 degrees. The hour hand is at an angle of 105 degrees, whereas the minute hand is at an angle of 180 degrees. For example, if we were given the time 3:30, our clock would look like this: We don't know, however, which hand has the bigger angle. So, we'll want to find the difference between these numbers. Now we know the angle of the minute hand, and the angle of the hour hand. In total, therefore, at 8:15, the hour hand is at an angle of 247.5 degrees. The fifteen minutes are another 15 * 0.5, or 7.5 degrees, more. When it's at the 8, the hour hand is 8 * 30, or 240 degrees past the 12. If we were given the time 8:15, we'd know the hour hand is a bit past the 8. Therefore, the angle of the hour hand can be calculated by multiplying the hour by 30, multiplying the minutes by 0.5, and adding those two results. Since there are 60 minutes in an hour, and the hour hand moves 30 degrees every 60 minutes, that means that the hour hand moves 30 / 60, or 0.5 degrees every minute. We need to know exactly how much that "bit" is. When it's 8:15, the hour hand is not directly on the 8. By that, I mean that the angle between the 12 (which is 0/360 degrees), and the minute hand is 120 degrees.Ĭalculating the angle of the hour hand is a bit trickier. If we were given the time 11:20, we know the minute hand is at 6 * 20, or 120 degrees. Since there are 60 minutes in an hour, each move of a minute hand is 360 / 60, or 6 degrees.Ĭalculating the angle of the minute hand, therefore, just means you multiply the number of minutes by 6. Since there are 12 hours, each slice between the hour is is 360 / 12, or 30 degrees. A clock, which is a circle, is 360 degrees. Because of that, in this post I'll spend longer on the "approach" section, and then will go into an explanation for how to code the solution. This problem is one of those that is less programming-based and more logic-based. By looking at a clock, you can see how the smaller angle between the hour and minute hand forms 90 degrees:īut if you were given a time like 8:15, you can't immediately tell that the angle is 157.5 degrees: Return the smaller angle (in degrees) formed between the hour and the minute hand. Today's algorithm is the Angle Between the Hands of a Clock Problem: 3 Finding the Only Single Number in an Array 4 Finding the Middle of a Linked List 5 Backspace String Comparisons: Two Ways To Approach a Common Algorithm 6 The Stock Span Problem: Using Stacks To Keep Track Of What's Been Seen 7 Finding the Kth Smallest Element: Walking Through How To Use Depth First Search on a Binary Search Tree 8 The Boyer-Moore Majority Vote Algorithm: Finding the Majority Element in an Array 9 Sorting Characters in a String By Their Frequency 10 Finding the Intersection of Two Arrays 11 Finding the Minimum Path Sum in a Grid with Dynamic Programming 12 Floyd's Tortoise and Hare Algorithm: Finding a Cycle in a Linked List 13 The Sieve of Eratosthenes: Counting the Number of Primes 14 Add Two Numbers Problems: How to Sum Two Linked Lists 15 The Longest Substring With No Repeating Characters 16 Merging Sorted Lists, Two Ways 17 Finding the Longest Common Prefix 18 Reversing a String in Place 19 The ZigZag Conversion Problem 20 The Longest Palindromic Substring: Solving the Problem Using Constant Space 21 Removing an Element in an Array In-Place 22 Solving the Best Time to Buy and Sell Stocks Problem in One Pass 23 Don't Underestimate the Two Pointers: Removing the N-th Node from the End of a Linked List 24 Not an "Easy" Algorithm: Rotating an Array, Three Ways 25 Sudoku Part I: Is the Board Valid? 26 Searching an Array, Two Ways 27 The Climbing Staircase Problem: How to Solve It, and Why the Fibonacci Numbers are Relevant 28 Transposing and Reversing: How to Rotate a 2D Matrix 90 Degrees 29 Turning 38 into 2: How to Solve the Add Digits Problem 30 The Gauss Sum, and Solving for the Missing Number 31 Is this Number the Sum of Two Square Integers? Solving The Sum of Squares Algorithm Two Ways 32 The Word Pattern Algorithm: How to Test if a String Follows a Pattern 33 Finding the Intersection of Two Arrays 34 Top Interview Question: Finding the First Unique Character in a String using Linear Time 35 Solving Pascal's Triangle in JavaScript 36 The Maximum Number of Events Problem 37 Solving Binary Tree Algorithms Using Recursion and Queues 38 From "hello world" to "world hello": Reversing the Words in a String 39 Finding the Most Frequent Elements in an Array 40 Finding the Angle Between the Hands of a Clock 41 The Container with the Most Water: Solving an Algorithm about Areas 1 The Happy Number Problem 2 Kadane's Algorithm & The Maximum Subarray Problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |