Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate) and 'R' (reverse):
When you get an instruction 'A', your car does the following:
position += speed
speed *= 2
When you get an instruction 'R', your car does the following:
If your speed is positive then speed = -1
otherwise speed = 1
Your position stays the same.
For example, after commands "AAR", your car goes to positions 0 -- 1 -- 3 -- 3, and your speed goes to 1 -- 2 -- 4 -- -1.
Given a target position target, return the length of the shortest sequence of instructions to get there.
Input: target = 6
Output: 5
Explanation:
The shortest instruction sequence is "AAARA".
Your position goes from 0 -- 1 -- 3 -- 7 -- 7 -- 6.
LeetCode Solutions: • LeetCode Solutions | Leetcode Questions
*** Best Books For Data Structures & Algorithms for Interviews:*********
1. Cracking the Coding Interview: https://amzn.to/2WeO3eO
2. Cracking the Coding Interview Paperback: https://amzn.to/3aSSe3Q
3. Coding Interview Questions - Narasimha Karumanchi: https://amzn.to/3cYqjkV
4. Data Structures and Algorithms Made Easy - N. Karumanchi: https://amzn.to/2U8FrDt
5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: https://amzn.to/2U0qZgY
6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: https://amzn.to/2Wdp8rZ
*****************************************************************************
Top 10 Google Coding Interview Questions: • Top 10 Google Coding Interview Questions
Top 10 Microsoft Coding Interview questions: • Top 10 Microsoft Coding Interview Questions
Top 10 Amazon Coding Interview Questions: • Top 10 Amazon Coding Interview Questions
Top 10 Apple Coding Interview Questions: • Top 10 Apple Coding Interview Questions
Top 10 Meta Coding Interview Questions: • Top 10 Meta Coding Interview Questions | T...
Data Structures course on Skillshare: https://skl.sh/3tvDxyP
data Structures course on Udemy: https://www.udemy.com/course/data-str...
Race Car | LeetCode 818
Facebook Coding Interview question,
google coding interview question,
leetcode,
Race Car,
Race Car C++,
Race Car Java,
Race Car python,
Race Car solution,
818. Race Car,
#Programming #datastructures #CodingInterview #LeetCode #Google #Amazon #median #dynamicprogramming