Java & Javascript Solution For HackerRank Problem: Beautiful Days at the Movies
Solving HackerRank Problem: Beautiful Days at the Movies using Java and javascript
Problem
Given a range of numbered days, [i..j] and a number k, determine the number of days in the range that are beautiful. Beautiful numbers are defined as numbers where | i - reverse(i) | is evenly divisible by k. If a day's value is a beautiful number, it is a beautiful day. Print the number of beautiful days in the range...
Complete the beautifulDays function in the editor below. It must return the number of beautiful days in the range...
See the full description of the problem Beautiful Days at the Movies
Solution
Simple brute-force is enough to solve this problem. Run a loop from i to j and for each number x check if abs(x - reverseOfX) % k === 0; if it does it's a Beautiful day
Time complexity: O(n) //Iterate over each test case
Space complexity: O(1)
Credit: @github.com/RyanFehr
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.