Загрузка страницы

Race Car | Leetcode 818 | C++

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: https://www.youtube.com/playlist?list=PL1w8k37X_6L86f3PUUVFoGYXvZiZHde1S

**** 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: https://youtu.be/L2QR_w5NlWU
Top 10 Microsoft Coding Interview questions: https://youtu.be/gcW8XbJJMHo
Top 10 Amazon Coding Interview Questions: https://youtu.be/0X0tVO3oOqI
Top 10 Apple Coding Interview Questions: https://youtu.be/ca5aRYgc6AI
Top 10 Meta Coding Interview Questions: https://youtu.be/lv-C-8FrMA8
Data Structures course on Skillshare: https://skl.sh/3tvDxyP
data Structures course on Udemy: https://www.udemy.com/course/data-structures-and-algorithms-course-1/?referralCode=ED7E1E1457F4FD27FA77

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

Видео Race Car | Leetcode 818 | C++ канала Knowledge Center
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
14 сентября 2022 г. 19:00:25
00:30:26
Яндекс.Метрика