├── Step 1 - Learn the basics ├── Step 1.4 Know Basic Maths │ ├── 3.Check Palindrome.py │ ├── 2.Reverse a Number.py │ ├── 5.GCD Or HCF.py │ ├── 1. Count Digits.py │ └── 4.Palindrome.py ├── Step 1.1 - Things to Know in C++ │ └── Python IO │ │ ├── 8.Time Complexity.py │ │ ├── 6. For loops.py │ │ ├── 5. Array String.py │ │ ├── 1. User Input Output.py │ │ ├── 2. Data Types.py │ │ ├── 4. Switch Statement.py │ │ ├── 7. While loops.py │ │ └── 3. If Else statements.py ├── Step 1.6 Learn Basic Hashing │ ├── 1.Counting frequencies of array elements.py │ └── 2.Find the highest lowest frequency element.py ├── Step 1.5 Learn Basic Recursion │ ├── 4.Sum of first N numbers.py │ ├── 5.Factorial of N numbers.py │ ├── 2.Print name N times using recursion.py │ ├── 3.Print 1 to N using recursion.py │ ├── 4.Print N to 1 using recursion.py │ ├── 6.Reverse an array.py │ ├── 7.Check if a string is palindrome or not.py │ ├── 1.Understand recursion by print something N times.py │ └── 8.Fibonacci Number.py └── Step 1.2 Build-up Logical Thinking │ ├── CPP STL.py │ ├── Pattern1.py │ ├── Pattern3.py │ ├── Pattern2.py │ ├── Pattern5.py │ ├── Pattern4.py │ ├── Pattern6.py │ ├── Pattern21.py │ ├── Pattern14.py │ ├── Pattern15.py │ ├── Pattern16.py │ ├── Pattern13.py │ ├── Pattern8.py │ ├── Pattern18.py │ ├── Pattern11.py │ ├── Pattern7.py │ ├── Pattern10.py │ ├── Pattern17.py │ ├── Pattern9.py │ ├── Pattern12.py │ ├── Pattern19.py │ ├── Pattern20.py │ └── Pattern22.py ├── Step 2 Learn Important Sorting Techniques └── Step 2.1 Sorting-I │ ├── 3. Insertion Sort Algorithm.py │ ├── 1. Selection Sort Algorithm.py │ └── 2.Bubble Sort Algorithm.py └── README.md /Step 1 - Learn the basics/Step 1.4 Know Basic Maths/3.Check Palindrome.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/8.Time Complexity.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Step 2 Learn Important Sorting Techniques/Step 2.1 Sorting-I/3. Insertion Sort Algorithm.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.6 Learn Basic Hashing/1.Counting frequencies of array elements.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.6 Learn Basic Hashing/2.Find the highest lowest frequency element.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/4.Sum of first N numbers.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3C9KZ8G 2 | 3 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.4 Know Basic Maths/2.Reverse a Number.py: -------------------------------------------------------------------------------- 1 | # https://practice.geeksforgeeks.org/problems/reverse-bits3556/1 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Strivers A2Z DSA Sheet 2 | 3 | - [Check DSA Sheet](https://takeuforward.org/strivers-a2z-dsa-course/strivers-a2z-dsa-course-sheet-2/) 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/5.Factorial of N numbers.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3QugUVo 2 | # https://practice.geeksforgeeks.org/problems/reverse-a-string/1 -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/6. For loops.py: -------------------------------------------------------------------------------- 1 | # for loop 2 | 3 | for i in range(10, 0, -1): 4 | print(i, end=' ') 5 | 6 | # 10 9 8 7 6 5 4 3 2 1 -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/CPP STL.py: -------------------------------------------------------------------------------- 1 | # https://takeuforward.org/c/c-stl-tutorial-most-frequent-used-stl-containers/ 2 | 3 | # https://www.youtube.com/watch?v=RRVYpIET_RU 4 | 5 | # Java Collections 6 | 7 | Step 1.4 Know Basic Maths -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/5. Array String.py: -------------------------------------------------------------------------------- 1 | # Array 2 | lst = [i for i in range(10)] 3 | print(lst) 4 | 5 | # String 6 | text = "This is a text" 7 | print(text) 8 | 9 | 10 | ''' 11 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 12 | This is a text 13 | ''' -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/2.Print name N times using recursion.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3y2BiWz 2 | ''' 3 | class Solution { 4 | public: 5 | void printGfg(int n) { 6 | if(n==0) return; 7 | cout<<"GFG "; 8 | printGfg(n-1); 9 | } 10 | }; 11 | 12 | ''' -------------------------------------------------------------------------------- /Step 2 Learn Important Sorting Techniques/Step 2.1 Sorting-I/1. Selection Sort Algorithm.py: -------------------------------------------------------------------------------- 1 | n = 5 2 | lst = [13,46,24,52,20,9] 3 | 4 | print(lst) 5 | 6 | for i in range(n): 7 | print(lst) 8 | for j in range(i+1, n+1): 9 | 10 | if lst[i]>lst[j]: 11 | lst[i], lst[j]= lst[j], lst[i] 12 | 13 | print(lst) 14 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/3.Print 1 to N using recursion.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3w3qhDh 2 | 3 | class Solution{ 4 | public: 5 | //Complete this function 6 | void printNos(int n) 7 | { 8 | if(n==0){ 9 | return; 10 | } 11 | printNos(n-1); 12 | cout<<(n)<<" "; 13 | 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/4.Print N to 1 using recursion.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3LOkcBn 2 | 3 | class Solution{ 4 | public: 5 | //Complete this function 6 | void printNos(int n) 7 | { 8 | if(n==0){ 9 | return; 10 | } 11 | printNos(n-1); 12 | cout<<(n)<<" "; 13 | 14 | } 15 | }; 16 | 17 | cout<lst[j+1]: 9 | lst[j], lst[j+1] = lst[j+1], lst[j] 10 | return lst -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/Pattern11.py: -------------------------------------------------------------------------------- 1 | ''' 2 | https://practice.geeksforgeeks.org/problems/triangle-pattern-1661718455/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=pattern_11 3 | 4 | Input: 5 5 | 6 | Output: 7 | 1 8 | 0 1 9 | 1 0 1 10 | 0 1 0 1 11 | 1 0 1 0 1 12 | 13 | ''' 14 | 15 | n = 5 16 | for i in range(1, n+1): 17 | start=(i%2) 18 | for j in range(i): 19 | print(start, end=' ') 20 | start = 0 if start==1 else 1 21 | print() 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/2. Data Types.py: -------------------------------------------------------------------------------- 1 | # Data Types 2 | 3 | print(int(12)) 4 | print(float(12.10)) 5 | print(str('this is a text')) 6 | 7 | lst = [1,2,3,4,5] 8 | print(lst) 9 | # OR 10 | for i in range(len(lst)): 11 | print(i, end=' ') 12 | print() 13 | 14 | st = set([1,2,3,4,5]) 15 | print(st) 16 | # OR 17 | for i in range(len(st)): 18 | print(i, end=' ') 19 | print() 20 | 21 | # Output 22 | # 12 23 | # 12.1 24 | # this is a text 25 | # [1, 2, 3, 4, 5] 26 | # 0 1 2 3 4 27 | # {1, 2, 3, 4, 5} 28 | # 0 1 2 3 4 -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/4. Switch Statement.py: -------------------------------------------------------------------------------- 1 | # https://practice.geeksforgeeks.org/problems/java-switch-case-statement3529/1 2 | 3 | # Switch not exist in python instead use python if elif else 4 | 5 | 6 | #User function Template for python3 7 | import math.pi as PI 8 | 9 | class Solution: 10 | def switchCase(self, choice, arr): 11 | if choice==1: 12 | r = arr[0] 13 | pi*(r**2) 14 | else: 15 | # choice 2 16 | l, b = arr[0], arr[1] 17 | return l*b -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/Pattern7.py: -------------------------------------------------------------------------------- 1 | # https://practice.geeksforgeeks.org/problems/triangle-pattern-1661492263/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=pattern_7 2 | 3 | # Input: 5 4 | 5 | # Output: 6 | ''' 7 | * 8 | *** 9 | ***** 10 | ******* 11 | ********* 12 | ''' 13 | 14 | n = 5 15 | for i in range(1, n+1): 16 | space=' ' 17 | print(space*(n-i), end='') 18 | print('*'*(i), end='') 19 | print('*'*(i-1), end='') 20 | print() 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/7. While loops.py: -------------------------------------------------------------------------------- 1 | # While loop 2 | # n = 10 3 | # while n: 4 | # print(n, end=' ') 5 | # n-=1 6 | # 10 9 8 7 6 5 4 3 2 1 7 | 8 | # https://practice.geeksforgeeks.org/problems/while-loop-printtable/1 9 | 10 | # Input: n = 1 11 | # Output: 10 9 8 7 6 5 4 3 2 1 12 | 13 | # Input: n = 2 14 | # Output: 20 18 16 14 12 10 8 6 4 2 15 | 16 | 17 | def printTable(n): 18 | multiplier = 10 19 | while multiplier>0: 20 | print(multiplier*n, end=' ') 21 | multiplier-=1 22 | printTable(5) -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/Pattern10.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | https://practice.geeksforgeeks.org/problems/triangle-pattern-1661718013/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=pattern_10 4 | 5 | Input: 5 6 | 7 | Output: 8 | * 9 | * * 10 | * * * 11 | * * * * 12 | * * * * * 13 | * * * * 14 | * * * 15 | * * 16 | * 17 | 18 | ''' 19 | 20 | n = 5 21 | for i in range(1, n+1): 22 | print('* '*(i), end='') 23 | print() 24 | 25 | for i in reversed(range(1, n)): 26 | print('* '*(i), end='') 27 | print() -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.1 - Things to Know in C++/Python IO/3. If Else statements.py: -------------------------------------------------------------------------------- 1 | # https://practice.geeksforgeeks.org/problems/java-if-else-decision-making0924/0?category%5B%5D=Java&category%5B%5D=Java&difficulty%5B%5D=-2&page=1&query=category%5B%5DJavadifficulty%5B%5D-2page1category%5B%5DJava 2 | 3 | 4 | class Solution: 5 | def compareNM(self, n : int, m : int) -> str: 6 | if n==m: 7 | return "equal" 8 | elif n>m: 9 | return "greater" 10 | else: 11 | return "lesser" 12 | 13 | 14 | 15 | # O/P 16 | # 4 8 -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/1.Understand recursion by print something N times.py: -------------------------------------------------------------------------------- 1 | # https://practice.geeksforgeeks.org/problems/print-1-to-n-without-using-loops-1587115620/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=print-1-to-n-without-using-loops 2 | #include 3 | using namespace std; 4 | 5 | class Solution{ 6 | public: 7 | //Complete this function 8 | void printNos(int n) 9 | { 10 | if(n==0){ 11 | return; 12 | } 13 | printNos(n-1); 14 | cout<<(n)<<" "; 15 | 16 | } 17 | }; 18 | 19 | https://bit.ly/3y2BiWz -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/Pattern17.py: -------------------------------------------------------------------------------- 1 | ''' 2 | https://practice.geeksforgeeks.org/problems/triangle-pattern-1662285911/1/?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=pattern_17 3 | 4 | Input: 4 5 | Output: 6 | A 7 | ABA 8 | ABCBA 9 | ABCDCBA 10 | ''' 11 | 12 | n = 4 13 | for i in range(1, n+1): 14 | print(' '*(n-i), end='') 15 | count = ord('A') 16 | for j in range(1, i+1): 17 | print(chr(count), end='') 18 | count+=1 19 | 20 | count-=2 21 | for j in reversed(range(i-1)): 22 | print(chr(count), end='') 23 | count-=1 24 | print() 25 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.2 Build-up Logical Thinking/Pattern9.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | https://practice.geeksforgeeks.org/problems/pattern/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=pattern_9 4 | 5 | 6 | * 7 | * * 8 | * * * 9 | * * * * 10 | * * * * * 11 | * * * * * 12 | * * * * 13 | * * * 14 | * * 15 | * 16 | ''' 17 | 18 | n = 5 19 | for i in range(1, n+1): 20 | space=' ' 21 | print(space*(n-i), end='') 22 | print('* '*(i), end='') 23 | print() 24 | 25 | for i in reversed(range(1, n+1)): 26 | space=' ' 27 | print(space*(n-i), end='') 28 | print('* '*(i), end='') 29 | print() -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.4 Know Basic Maths/1. Count Digits.py: -------------------------------------------------------------------------------- 1 | ''' 2 | https://practice.geeksforgeeks.org/problems/count-digits5716/1 3 | Input: 4 | N = 12 5 | Output: 6 | 2 7 | Explanation: 8 | 1, 2 both divide 12 evenly 9 | 10 | Input: 11 | N = 23 12 | Output 13 | 0 14 | Explanation: 15 | 2 and 3, none of them 16 | divide 23 evenly 17 | 18 | ''' 19 | class Solution: 20 | def evenlyDivides (self, n): 21 | count = 0 22 | temp = n 23 | while n: 24 | d = n%10 25 | if d!=0: 26 | if temp%d==0: 27 | count+=1 28 | n//=10 29 | return count 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Step 1 - Learn the basics/Step 1.5 Learn Basic Recursion/8.Fibonacci Number.py: -------------------------------------------------------------------------------- 1 | # https://bit.ly/3QUkkk2 2 | 3 | 4 | 5 | class Solution 6 | { 7 | public: 8 | //Function to return list containing first n fibonacci numbers. 9 | vector printFibb(int n) 10 | { 11 | vector v; 12 | long long first=0, second=1, ans; 13 | if(n>=1){ 14 | v.push_back(second); 15 | } 16 | for(int i=1; i