1291. Sequential Digits Leetcode BFS Solution example and Code C++

preview_player
Показать описание
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.



Example 1:

Input: low = 100, high = 300
Output: [123,234]
Example 2:

Input: low = 1000, high = 13000
Output: [1234,2345,3456,4567,5678,6789,12345]

Check out our other playlists:

Dynamic Programming:

Trees:

Heaps and Maps:

Arrays and Maths:

Bit Manipulation:

Greedy Algorithms:

Sorting and Searching:

Strings:

Linked Lists:

Stack and Queues:

Two Pointers:

Graphs, BFS, DFS:

Backtracking:

Non- DSA playlists:

Probability:

SQL-Basic Join functions:

SQL-Basic Aggregate functions:
Рекомендации по теме
Комментарии
Автор

Hey Great explanation video ! Just wanted to say this!!

johnj
Автор

Code in C++:
queue<int>q;

for(int i=1;i<=9;i++)
q.push(i);

vector<int>ans;

while(!q.empty())
{ int num = q.front();

q.pop();
if(num>=low & num<=high)
ans.push_back(num);

if(num>high)break;
if(num%10<9)
int rem = num%10;

q.push(num*10+rem+1);

}


}

return ans;

probabilitycodingisfunis
Автор

Great Explanation
keep grinding
🚀🚀🚀

jayeshbhanushali
Автор

what is the time complexity of this algorithm?

uonliaquat
welcome to shbcf.ru