Programmers Zone
Programmers Zone
  • 141
  • 307 613
2400 Number of Ways to Reach a Position After Exactly k Steps | Zero to FAANG Kunal | Assignment
2400 Number of Ways to Reach a Position After Exactly k Steps | Zero to FAANG Kunal | Assignment | Leetcode | Shapnesh Tiwari
Problem link :
leetcode.com/problems/number-of-ways-to-reach-a-position-after-exactly-k-steps/
Complete Java + DSA + Interview Preparation + CP Course
czcams.com/play/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ.html
Hi, thanks for watching our video about Arrays in Java
In this video we’ll walk you through:
- Brute Force
- Efficient approach
- Solution Code
TIMESTAMPS
Intro
Explanation begins
IDE solution
ABOUT OUR CHANNEL
Our channel is all about Programming. We cover lots of cool stuff such as solution to problems, concept explanation and tricks to master CP
Check out our channel here:
czcams.com/channels/qtYay7YwH8JdZxDqpVEPvg.html
Don’t forget to subscribe!
CHECK OUT OUR OTHER Playlists
GeeksforGeeks playlist:
czcams.com/play/PLDaU_TBYXoirv-848r81oHLSArcBrjIe7.html
Complete C++ Course playlist:
czcams.com/play/PLDaU_TBYXoio9L1qRpTrtzK9JJAwFLMSj.html
CodeChef Playlist:
czcams.com/play/PLDaU_TBYXoip_JFIo0U-Nl2dNA_ZMsd2z.html
HackerRank playlist:
czcams.com/play/PLDaU_TBYXoirMjgzW59T_XMyT5yRZ7ht_.html
LeetCode problems
czcams.com/play/PLDaU_TBYXoirsirbg6feNCKk3oPRn6M7w.html
FIND US AT
www.waadanibhao.wordpress.com
GET IN TOUCH
Contact us on hopesalivenow@gmail.com
2400. Number of Ways to Reach a Position After Exactly k Steps
Medium
86
35
Add to List
Share
You are given two positive integers startPos and endPos. Initially, you are standing at position startPos on an infinite number line. With one step, you can move either one position to the left, or one position to the right.
Given a positive integer k, return the number of different ways to reach the position endPos starting from startPos, such that you perform exactly k steps. Since the answer may be very large, return it modulo 109 + 7.
Two ways are considered different if the order of the steps made is not exactly the same.
Note that the number line includes negative integers.
Example 1:
Input: startPos = 1, endPos = 2, k = 3
Output: 3
Explanation: We can reach position 2 from 1 in exactly 3 steps in three ways:
- 1 - 2 - 3 - 2.
- 1 - 2 - 1 - 2.
- 1 - 0 - 1 - 2.
It can be proven that no other way is possible, so we return 3.
Example 2:
Input: startPos = 2, endPos = 5, k = 10
Output: 0
Explanation: It is impossible to reach position 5 from position 2 in exactly 10 steps.
#codechef #coding #python #hackerrank #programming #java #computerscience #coder #code #competitiveprogramming #machinelearning #pythonprogramming #algorithms #cpp #javascript #hackerearth #webdeveloper #geeksforgeeks #codinglife #leetcode #c #codeforces #engineering #codingmemes #programmer #hacker #programmingmemes #topcoder #webdevelopment #bhfyp #DSAwithKunal
zhlédnutí: 612

Video

2399 Check Distances Between Same Letters | Zero to FAANG Kunal | Assignment Solution | Leetcode
zhlédnutí 596Před rokem
2399 Check Distances Between Same Letters | Zero to FAANG Kunal | Assignment Solution | Leetcode | Shapnesh Tiwari Problem link : leetcode.com/contest/weekly-contest-309/problems/check-distances-between-same-letters/ Complete Java DSA Interview Preparation CP Course czcams.com/play/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ.html Hi, thanks for watching our video about Arrays in Java In this video we’ll...
2375 Construct Smallest Number From DI String | Zero to FAANG | Striver SDE Sheet | Shapnesh | WE2
zhlédnutí 381Před rokem
2375 Construct Smallest Number From DI String | Zero to FAANG | Striver SDE Sheet | Shapnesh | WE2 @Striver Problem link : leetcode.com/problems/construct-smallest-number-from-di-string/ Hi, thanks for watching our video about Strings In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our ch...
2315 Count Asterisks | Zero to FAANG | Weekly 296 | Striver SDE Sheet | Shapnesh | WE2
zhlédnutí 748Před 2 lety
2315 Count Asterisks | Zero to FAANG | Weekly 296 | Striver SDE Sheet | Shapnesh | WE2 @Striver Problem link : leetcode.com/problems/count-asterisks/ Hi, thanks for watching our video about Strings In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Programming. We co...
2295 Replace Elements in an Array | Zero to FAANG | Weekly 296 | Striver SDE Sheet | Shapnesh | WE2
zhlédnutí 666Před 2 lety
2293 Min Max Game | Zero to FAANG | Weekly 294 | Leetcode | Striver SDE Sheet | Shapnesh | WE2 @striver_79 Problem link : leetcode.com/problems/replace-elements-in-an-array/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all a...
2294 Partition Array Such That Maximum Difference Is K | Zero to FAANG | Weekly 296 | Striver | WE2
zhlédnutí 587Před 2 lety
2293 Min Max Game | Zero to FAANG | Weekly 294 | Leetcode | Striver SDE Sheet | Shapnesh | WE2 Problem link : leetcode.com/problems/partition-array-such-that-maximum-difference-is-k/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel...
2293 Min Max Game | Zero to FAANG | Weekly 296 | Leetcode | Striver SDE Sheet | Shapnesh | WE2
zhlédnutí 470Před 2 lety
2293 Min Max Game | Zero to FAANG | Weekly 294 | Leetcode | Striver SDE Sheet | Shapnesh | WE2 Problem link : leetcode.com/problems/min-max-game/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Programming. We cover l...
2280 Minimum Lines to Represent a Line Chart | Zero to FAANG | Weekly 294 | Leetcode | WE2
zhlédnutí 232Před 2 lety
2280 Minimum Lines to Represent a Line Chart | Zero to FAANG | Weekly 294 | Leetcode | WE2 Problem link : leetcode.com/problems/minimum-lines-to-represent-a-line-chart/ Hi, thanks for watching our video about 2D Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all abo...
2279 Maximum Bags With Full Capacity of Rocks | Zero to FAANG | Weekly 294 | Leetcode | Striver
zhlédnutí 936Před 2 lety
2279 Maximum Bags With Full Capacity of Rocks | Zero to FAANG | Weekly 294 | Leetcode | Striver Problem link : leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/ Hi, thanks for watching our video about Strings In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all...
2278 Percentage of Letter in String | Zero to FAANG | Weekly 294 | Leetcode | Striver | WE2
zhlédnutí 343Před 2 lety
2278 Percentage of Letter in String | Zero to FAANG | Weekly 294 | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/percentage-of-letter-in-string/ Hi, thanks for watching our video about Strings In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Program...
2270 Number of Ways to Split Array | Zero to FAANG | Solution | Leetcode | Striver | WE2
zhlédnutí 592Před 2 lety
2270 Number of Ways to Split Array | Zero to FAANG | Solution | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/number-of-ways-to-split-array/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Programming....
2269 Find the K Beauty of a Number | Zero to FAANG | Solution | Leetcode | Striver | WE2
zhlédnutí 833Před 2 lety
2269 Find the K Beauty of a Number | Zero to FAANG | Solution | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/find-the-k-beauty-of-a-number/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Programming....
2265 Count Nodes Equal to Average of Subtree | Zero to FAANG | Solution | Leetcode | Striver | WE2
zhlédnutí 2KPřed 2 lety
2265 Count Nodes Equal to Average of Subtree | Zero to FAANG | Solution | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/count-nodes-equal-to-average-of-subtree/ Hi, thanks for watching our video about Trees In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all...
2264 Largest 3 Same Digit Number in String | Zero to FAANG | Solution | Leetcode | Striver | WE2
zhlédnutí 908Před 2 lety
2264 Largest 3 Same Digit Number in String | Zero to FAANG | Solution | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/largest-3-same-digit-number-in-string/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all ab...
2256 Minimum Average Difference | Zero to FAANG | Assignment Solution | Leetcode | Striver | WE2
zhlédnutí 1,1KPřed 2 lety
2256 Minimum Average Difference | Zero to FAANG | Assignment Solution | Leetcode | Striver | WE2 Problem link : leetcode.com/problems/minimum-average-difference/ Hi, thanks for watching our video about Arrays In this video we’ll walk you through: - Brute Force - Efficient approach - Solution Code TIMESTAMPS Intro Explanation begins IDE solution ABOUT OUR CHANNEL Our channel is all about Program...
2255 Count Prefixes of a Given String | Zero to FAANG | Assignment Solution | Leetcode | Striver
zhlédnutí 817Před 2 lety
2255 Count Prefixes of a Given String | Zero to FAANG | Assignment Solution | Leetcode | Striver
2248. Intersection of Multiple Arrays | Zero to FAANG | Assignment Solution | Leetcode | Striver
zhlédnutí 796Před 2 lety
2248. Intersection of Multiple Arrays | Zero to FAANG | Assignment Solution | Leetcode | Striver
682 Baseball Game | Zero to FAANG | Assignment Solution | Leetcode | Striver | WE2 | Shapnesh
zhlédnutí 346Před 2 lety
682 Baseball Game | Zero to FAANG | Assignment Solution | Leetcode | Striver | WE2 | Shapnesh
215 Kth Largest Element in an Array | 703. Kth Largest Element in a Stream | Priority Queue | WE2
zhlédnutí 178Před 2 lety
215 Kth Largest Element in an Array | 703. Kth Largest Element in a Stream | Priority Queue | WE2
454 4Sum II | Zero to FAANG | Assignment Solution | Leetcode | Shapnesh | Programmers Zone
zhlédnutí 244Před 2 lety
454 4Sum II | Zero to FAANG | Assignment Solution | Leetcode | Shapnesh | Programmers Zone
Good Weather(GOODWEAT) | CodeChef Practice(Beginner) | CodeChef | Complete Solutions
zhlédnutí 556Před 2 lety
Good Weather(GOODWEAT) | CodeChef Practice(Beginner) | CodeChef | Complete Solutions
1346 Check If N and Its Double Exist | Zero to FAANG | Assignment Solution | Leetcode | Shapnesh
zhlédnutí 2,8KPřed 2 lety
1346 Check If N and Its Double Exist | Zero to FAANG | Assignment Solution | Leetcode | Shapnesh
1089. Duplicate Zeros | Zero to FAANG Kunal | Assignment Solution | Leetcode | Shapnesh
zhlédnutí 3,3KPřed 2 lety
1089. Duplicate Zeros | Zero to FAANG Kunal | Assignment Solution | Leetcode | Shapnesh
Equal Or Not Equal | CodeForces | Educational Codeforces Round 119 (Rated for Div. 2) | Shapnesh
zhlédnutí 332Před 2 lety
Equal Or Not Equal | CodeForces | Educational Codeforces Round 119 (Rated for Div. 2) | Shapnesh
Equal Coins (EQUALCOIN) | Codechef Long November | November Challenge 2021 Division 3
zhlédnutí 4,1KPřed 2 lety
Equal Coins (EQUALCOIN) | Codechef Long November | November Challenge 2021 Division 3
Which Fuel is Cheaper (CHEAPFUEL) | Codechef Long November | November Challenge 2021 Division 3
zhlédnutí 2,6KPřed 2 lety
Which Fuel is Cheaper (CHEAPFUEL) | Codechef Long November | November Challenge 2021 Division 3
DSA | Binary Search | lecture 02 | Best explanation of Binary Search in arrays
zhlédnutí 283Před 2 lety
DSA | Binary Search | lecture 02 | Best explanation of Binary Search in arrays
DSA | linear Search | lecture 01 | Best explanation of linear Search in arrays
zhlédnutí 136Před 2 lety
DSA | linear Search | lecture 01 | Best explanation of linear Search in arrays
2011 Final Value of Variable After Performing Operations | Zero to FAANG Kunal | Leetcode | Shapnesh
zhlédnutí 4,4KPřed 2 lety
2011 Final Value of Variable After Performing Operations | Zero to FAANG Kunal | Leetcode | Shapnesh
Longest AND Subarray (ANDSUBAR) | Codechef Long October | October Challenge 2021 Division 3 (Rated)
zhlédnutí 7KPřed 2 lety
Longest AND Subarray (ANDSUBAR) | Codechef Long October | October Challenge 2021 Division 3 (Rated)

Komentáře

  • @ashking569
    @ashking569 Před 3 dny

    kunal and you are doing an excellent job ! Thank You <3

  • @rohitrana5701
    @rohitrana5701 Před 16 dny

    Leet code ki easy solutions bhi medium level ke hai

  • @rohitrana5701
    @rohitrana5701 Před 16 dny

    It seema to be little difficult for beginners who have directly come for solving questions after understanding the concept of array.😢😢😢😢😢. logic of solving this Question didn't strike in my mind..

  • @GK-lm2rw
    @GK-lm2rw Před 19 dny

    Nice Explanation sir..

  • @ashaysaoji2273
    @ashaysaoji2273 Před měsícem

    Great explnation man!

  • @meme-ku1vs
    @meme-ku1vs Před měsícem

    thanks,btw nice explanation ✔✔❣❣

  • @SubhajitDas-mt7sn
    @SubhajitDas-mt7sn Před měsícem

    class Solution { public: int finalValueAfterOperations(vector<string>& operations) { int x = 0; int n = operations.size(); for (int i = 0;i <n;i++){ if(operations[i] == "++X" || operations[i] == "X++"){ x++; } else{ x--; } } return x; } };

  • @sourabhsharma2511
    @sourabhsharma2511 Před 2 měsíci

    good work bro !!!!!!!!!!!

  • @rituraj_79
    @rituraj_79 Před 2 měsíci

    pen paper leh le bhai usmai humlogo ko better dikhaga

  • @shinobiworld860
    @shinobiworld860 Před 2 měsíci

    Nice thanks

  • @abhikumarr7306
    @abhikumarr7306 Před 2 měsíci

    Compilation Error ./Solution.cpp: In function 'void iter(std::vector<int>::iterator, std::vector<int>::iterator)': ./Solution.cpp:19:22: error: 'it' was not declared in this scope for(it1;it1!=it2;it++)

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 Před 2 měsíci

    NICE SUPER EXCELLENT MOTIVATED

  • @rishabhsinghal138
    @rishabhsinghal138 Před 3 měsíci

    use LinkedList to improve the time complexity as insertion is O(1) in LinkedList and O(n) in array list

  • @dibbodas4116
    @dibbodas4116 Před 3 měsíci

    why the time complexity is not o(n*m)

  • @SouravCheck
    @SouravCheck Před 3 měsíci

    why my code is not running var twoSum = function(nums, target) { for(let i=0;i<nums.length;i++) { for(j=i+1;j<nums.length;j++) { if((nums[i]+nums[j])==target) { console.log("the indices where target matched is="); console.log("["+i+","+j+"]"); } } } };]

    • @hastar076
      @hastar076 Před 24 dny

      run the first loop till nums.length - 1

  • @clevercoderjoy
    @clevercoderjoy Před 4 měsíci

    iska logic kaise banaya bhai? mai kaise aise sochna seekh pau? ye to mai soch hi nhi skta tha kbhi to

  • @hari7110
    @hari7110 Před 4 měsíci

    bro help why its not passing all test case? it tried to solve using binary search import java.util.Arrays; class Solution { public boolean checkIfExist(int[] arr) { Arrays.sort(arr); for (int i = 0; i < arr.length; i++) { if (binarySearch(arr, arr[i], i)) { return true; } } return false; } private boolean binarySearch(int[] arr, int target, int i) { int start = 0; int end = arr.length - 1; while (start <=end) { int mid = start + (end - start) / 2; if ((mid != i)&&(arr[mid]/2 == target )) { return true; } else if (arr[mid] < target && mid!=0) { start = mid + 1; } else { end = mid - 1; } } return false; } }

  • @user-js1rx8rs9p
    @user-js1rx8rs9p Před 4 měsíci

    nums=[0,2,1,5,3,4] result1=[] for i in range(len(nums)): result=nums[nums[i]] result1.append(result) print(result1)

  • @PrakashKumar-pf5st
    @PrakashKumar-pf5st Před 4 měsíci

    thank u brother ,

  • @srijansrivastav9637
    @srijansrivastav9637 Před 5 měsíci

    Thank you bro

  • @hemantyadav1047
    @hemantyadav1047 Před 5 měsíci

    IN while loop, it should be greater than or equal to 1

  • @gitansh194
    @gitansh194 Před 5 měsíci

    nice explanation

  • @harshsharma9322
    @harshsharma9322 Před 5 měsíci

    Thankyou man!

  • @AkshatKumar-lp7qk
    @AkshatKumar-lp7qk Před 6 měsíci

    Since it is given that 0<=nums[i]<=n, there is need to do mod with n.

  • @Dekh_rha_hai_vinod.
    @Dekh_rha_hai_vinod. Před 6 měsíci

    Bro 1920 ???

  • @bharatmehta30
    @bharatmehta30 Před 6 měsíci

    Loved this explanation and concept. Thank you

  • @user-ym8fw3is5w
    @user-ym8fw3is5w Před 6 měsíci

    how did you come up with this approach? I mean the thought process

  • @harshityadav6817
    @harshityadav6817 Před 7 měsíci

    2:47 bich wala flip nhi krenge agar 3*3 ki matrix hui but agar 4*4 ki matrix hui toh kyuki agr 4*4 Me pura flip krenge toh bech me pura flip hoga na. Im bit confused here

  • @Jaydoshi77
    @Jaydoshi77 Před 7 měsíci

    spiral matrix 3 wala solve kro plez............

  • @Jaydoshi77
    @Jaydoshi77 Před 7 měsíci

    bhai spiral matrix 3 ispe video banao plez

  • @kalpitgudigar
    @kalpitgudigar Před 8 měsíci

    tysm for the explanation

  • @plutomessi21
    @plutomessi21 Před 8 měsíci

    thanks bhaiya

  • @PadmanabanN-ue4xd
    @PadmanabanN-ue4xd Před 9 měsíci

    Thank you brother

  • @anonymousnoob3660
    @anonymousnoob3660 Před 9 měsíci

    Excellent explanation!

  • @akhileshkumbar4864
    @akhileshkumbar4864 Před 9 měsíci

    improve handwriting please

  • @bkmeher9005
    @bkmeher9005 Před 9 měsíci

    Thanks brother

  • @pushpendrasingh777
    @pushpendrasingh777 Před 9 měsíci

    In question it is written that we have to return the first occurrence of the max year which will be not the case with brute force solution

  • @aayushranjan5572
    @aayushranjan5572 Před 10 měsíci

    yrr code linke de dena chaey tha tb hm c++ me convert kr lete

  • @Pratik_yadaw
    @Pratik_yadaw Před 10 měsíci

    he is confused as well and making us confusee

  • @funnyduniya4574
    @funnyduniya4574 Před 10 měsíci

    Brilliant🎉

  • @beastslayer1207
    @beastslayer1207 Před 10 měsíci

    why u placed the king at( 3,3 )coordinate only

  • @chnihar4123
    @chnihar4123 Před 11 měsíci

    Nice explanation

  • @chnihar4123
    @chnihar4123 Před 11 měsíci

    Great explanation

  • @lostsky7656
    @lostsky7656 Před 11 měsíci

    👏🔥 Kudos to you for this amazing video! Keep up the fantastic work! 🚀💡

  • @JohnWickea
    @JohnWickea Před 11 měsíci

    guess fn kaha gaya ? gemd me dal liye kya guess fn

  • @rohanpandey4324
    @rohanpandey4324 Před 11 měsíci

    bro you should use a black pen instead of red

  • @saumyagupta7400
    @saumyagupta7400 Před 11 měsíci

    what is math.log10()?? how does it works?

  • @abhishekkr8077
    @abhishekkr8077 Před 11 měsíci

    Good explanation bro bs ye mat[n-1-i] wla logic nhi samajh aaya ? Bata do koi agar janta hai toh

  • @user-di3di7iu8p
    @user-di3di7iu8p Před 11 měsíci

    nice explain sir😊

  • @akshitrawat-gv2bh
    @akshitrawat-gv2bh Před rokem

    worst explaination ever