An Evening of Movies
Updated
Problem statement
Christine and her friends are planning a movie marathon using her family's massive film library. They want to start with shorter movies and progress onto longer movies, but they're going to do it in a very specific way: each movie they watch must be the same length as the previous movie, or exactly one minute longer than the previous movie (counting opening and closing credits, of course). The first movie they watch can have any length. They do not want to watch any of the movies twice, even if they're not back-to-back. Popcorn will be provided.
Assume that Christine and her friends plan their movie marathon optimally. Implement the following function in the code editor to determine the maximum number of movies that the group can watch according to their rules.
Complete the function longestMarathon in the editor.
longestMarathon has the following parameter:
int[] runtimes: an array of integers representing the collection of movie runtimes
int: the length of the largest sequence of non-repeated movies that the group can watch, such that the Nth movie in the sequence has the same runtime as, or is exactly one minute longer than, the (N-1)st movie. A return value of 0 indicates that it is not possible for the group to have a marathon at all.
Function
longestMarathon(runtimes: int[]) → intExamples
Example 1
runtimes = [8, 4, 5, 7, 4]return = 3Consider a film library that consists of 5 films whose runtimes are [8, 4, 5, 7, 4].
- If the group starts with film 0 whose runtime is 8, their marathon will have length 1, as all the other movies have shorter runtimes.
- If the group starts with film 1 or film 4, each of which has a runtime of 4, they have two options to progress:
- They can watch the other film with a runtime of 4, and then film 2 whose runtime is 5, giving their marathon a length of 3
- They can immediate jump to film 2 whose runtime is 5, giving their marathon a length of 2
- If the group starts with film 2 whose runtime is 5, their marathon will have length 1, as there are no other film whose runtime is either 5 or 6
- If the group starts with film 3 whose runtime is 7, they can then watch film 0 whose runtime is 8, giving their marathon a length of 2
The function should therefore return 3.
More Akuna Capital interview questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
Similar questions at other companies
- Min OperationAmazon · OA
- Make Layer Times OddPatreon · OAPatreon interview questions
- Min Cost to Complete All ProjectsSalesforce · OASalesforce interview questions
- Freelancing PlatformJP Morgan Chase · OAJP Morgan Chase interview questions
- Maximum Distinct Values After Cross-Array SwapsScale AI · OAScale AI interview questions
- Minimum Operations to Make a SubsequenceGoogle · OAGoogle interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)