├── .gitignore ├── Cheatsheets_and_notes ├── C++_Cheatsheet_CodeWithHarry.pdf ├── DSA_CompleteNotes.pdf └── DSA_TopicWise_Notes │ └── DSA_TopicWise_Notes │ ├── 1. Chapter-0 (Basics) │ └── ds0.pdf │ ├── 2. Time Complexity & Big O Notation │ └── ds1.pdf │ ├── 3-Asymptotic_Notations │ └── Asymptotic_Notations.pdf │ ├── 4-Best_Worst_Average │ └── Best_Worst_Average.pdf │ ├── 5-ADTs │ ├── ADTs.one │ ├── ADTs.pdf │ ├── Algorithms.one │ └── Open Notebook.onetoc2 │ ├── 6-ArrayOperations │ └── Array_Operations.pdf │ ├── 7-LinearVsBinary │ └── LinearVsBinary.pdf │ ├── 8-Linked Lists │ ├── 1-LinkedLists.pdf │ ├── 2-Linked_List_Deletion.pdf │ ├── 3-Circular_Linked_Lists.pdf │ └── 4-DoublyLinkedLists.pdf │ └── 9-Stack │ └── Introduction_To_Stack.pdf ├── Course_outline.png ├── LICENSE ├── README-image.jpg ├── README.md ├── competitive-programming-resources └── awesome-competitive-programming-master │ ├── .travis.yml │ ├── CONTRIBUTING.md │ ├── LICENSE.md │ ├── README.md │ ├── README.pdf │ ├── _config.yml │ └── index.md ├── contests_solutions ├── 1st-contest │ ├── Apple_shop_with_ninja.cpp │ ├── Draw_the_diamond.cpp │ ├── Maximize_X.cpp │ └── Three_way_split.cpp └── 2nd-contest │ ├── 1-Class_test.cpp │ ├── 2-Binary_shopping.cpp │ ├── 3-Longest_subarray.cpp │ └── 4-Light_up_street.cpp ├── lecture-001=Flowcharts ├── Lecture1-handwritten.pdf ├── Lecture1.pdf └── notes.txt ├── lecture-002=First_program ├── Lecture2.pdf ├── code.cpp └── notes.txt ├── lecture-003=Conditionals_&_loops ├── Conditionals_and_loops.pdf ├── code.cpp ├── lec-3_notes.pdf └── notes.txt ├── lecture-004=Pattern_problems ├── Lecture4.pdf ├── Solving_pattern_questions(Part-2).pdf ├── code.cpp └── notes.txt ├── lecture-005=Bitwise_&_operator_precedence ├── Bitwise Operators, For Loops, Operator Precedence.pdf ├── Lecture5.pdf ├── code.cpp └── notes.txt ├── lecture-006=Binary_&_decimal_num_system ├── Decimal and Binary System.pdf ├── Lecture6.pdf ├── code.cpp └── notes.txt ├── lecture-007=Leetcode_session ├── Lecture7.pdf ├── LeetCode Problem Solving Session.pdf ├── code.cpp └── notes.txt ├── lecture-008=Switch-case_&_functions ├── Function.pdf ├── code.cpp └── notes.txt ├── lecture-009=Introduction_to_arrays ├── Arrays.pdf ├── code.cpp └── notes.txt ├── lecture-010=Leetcode_session ├── Array Questions.pdf ├── code.cpp └── notes.txt ├── lecture-011=Time_&_space_complexity ├── Complexity1.pdf └── notes.txt ├── lecture-012=Binary_search ├── Binary Search I.pdf ├── code.cpp └── notes.txt ├── lecture-013=Leetcode_session ├── Binary Search I.pdf ├── code.cpp └── notes.txt ├── lecture-014=LeetCode_session ├── Binary Search Ques2.pdf ├── code.cpp └── notes.txt ├── lecture-015=Leetcode_session ├── Binary Search Question3.pdf ├── code.cpp └── notes.txt ├── lecture-016=Selection_sort ├── Selection Sort.pdf ├── code.cpp └── notes.txt ├── lecture-017=Bubble_sort ├── Bubble Sort.pdf ├── code.cpp └── notes.txt ├── lecture-018=Insertion_sort ├── Insertion Sort.pdf ├── code.cpp └── notes.txt ├── lecture-019=STL_in_one_video ├── code.cpp └── notes.txt ├── lecture-020=Leetcode_session ├── Lecture 20.pdf ├── code.cpp └── notes.txt ├── lecture-021=LeetCode_session ├── Lecture 21.pdf ├── code.cpp └── notes.txt ├── lecture-022=Char_arrays_&_strings ├── Strings.pdf ├── code.cpp └── notes.txt ├── lecture-023=Intro_to_2D_arrays ├── ArrayExercises.pdf ├── code.cpp └── notes.txt ├── lecture-024=Basic_math_for_DSA ├── code.cpp └── notes.txt ├── lecture-025=Pointers_part-1 ├── code.cpp └── notes.txt ├── lecture-026=Pointers_part-2 ├── code.cpp └── notes.txt ├── lecture-027=Double_pointers ├── code.cpp └── notes.txt ├── lecture-028=Reference_variable ├── code.cpp └── notes.txt ├── lecture-029=Dynamic_memory_2D_array ├── code.cpp └── notes.txt ├── lecture-030=Macros_&_global_variable ├── code.cpp └── notes.txt ├── lecture-031=Recursion_day-1 ├── code.cpp └── notes.txt ├── lecture-032=Recursion_day-2 ├── code.cpp └── notes.txt ├── lecture-033=Recursion_binary_search ├── code.cpp └── notes.txt ├── lecture-034=Recursion_in_strings ├── code.cpp └── notes.txt ├── lecture-035=Merge_sort_using_recursion ├── code.cpp └── notes.txt ├── lecture-036=Quick_sort_using_recursion ├── code.cpp └── notes.txt ├── lecture-037=Recursion_subsets_of_strings ├── code.cpp └── notes.txt ├── lecture-038=Phone_keypad_problem ├── code.cpp └── notes.txt ├── lecture-039=Permutations_of_strings ├── code.cpp └── notes.txt ├── lecture-040=Rat_in_maze_problem ├── code.cpp └── notes.txt ├── lecture-041=TC_&_SC_in_recursion ├── code.cpp └── notes.txt ├── lecture-042=OOPS_introduction ├── code.cpp └── notes.txt ├── lecture-043=OOPS_4_pillars ├── code.cpp └── notes.txt ├── lecture-044=Linkedlist_introduction ├── code.cpp └── notes.txt ├── lecture-045=Linkedlist_questions ├── code.cpp └── notes.txt ├── lecture-046=Linkedlist_questions ├── code.cpp └── notes.txt ├── lecture-047=Remove_loop_in_linkedlist ├── code.cpp └── notes.txt ├── lecture-048=Remove_duplicates_linkedlist ├── code.cpp └── notes.txt ├── lecture-049=Merge_sorted_linkedlist ├── code.cpp └── notes.txt ├── lecture-050=Check_palindrome_linkedlist ├── code.cpp └── notes.txt ├── lecture-051=Add_2_numbers_linkedlist ├── code.cpp └── notes.txt ├── lecture-052=Clone_linkedlist_pointers ├── code.cpp └── notes.txt ├── lecture-053=Merge_sort_linkedlist ├── code.cpp └── notes.txt ├── lecture-054=Stack_intro ├── code.cpp └── notes.txt ├── lecture-055=Stack_questions ├── code.cpp └── notes.txt ├── lecture-056=Largest_rectangular_histogram ├── code.cpp └── notes.txt ├── lecture-057=Stack_celebrity_problem ├── code.cpp └── notes.txt ├── lecture-058=N_stack_in_array ├── code.cpp └── notes.txt ├── lecture-059=Special_stack_problem ├── code.cpp └── notes.txt ├── lecture-060=Queues_introduction ├── code.cpp └── notes.txt ├── lecture-061=Queues_questions ├── code.cpp └── notes.txt ├── lecture-062=Binary-tree_intro ├── code.cpp └── notes.txt ├── lecture-063=Binary-tree_questions ├── code.cpp └── notes.txt ├── lecture-064=Binary-tree_questions ├── code.cpp └── notes.txt ├── lecture-065=Binary-tree_questions ├── code.cpp └── notes.txt ├── lecture-066=Constructing_binary-tree ├── code.cpp └── notes.txt ├── lecture-067=Time_to_burn_binary-tree ├── code.cpp └── notes.txt ├── lecture-068=Morris_traversal ├── code.cpp └── notes.txt ├── lecture-070=BST_questions ├── code.cpp └── notes.txt ├── lecture-071=BST_questions ├── code.cpp └── notes.txt ├── lecture-072=Merge_two_BST ├── code.cpp └── notes.txt ├── lecture-073=Largest_BST ├── code.cpp └── notes.txt ├── lecture-074=Heaps_intro ├── code.cpp └── notes.txt ├── lecture-075=Heaps_questions ├── code.cpp └── notes.txt ├── lecture-076=Heaps_questions ├── code.cpp └── notes.txt ├── lecture-077=Heaps_questions ├── code.cpp └── notes.txt ├── lecture-078=Hashmaps_intro ├── code.cpp └── notes.txt ├── lecture-079=Trie_intro ├── code.cpp └── notes.txt ├── lecture-080=Longest_common_prefix_trie ├── code.cpp └── notes.txt ├── lecture-081=Phone_directory_using_trie ├── code.cpp └── notes.txt ├── lecture-082=Backtracking_day-1 ├── code.cpp └── notes.txt ├── lecture-083=Backtracking_day-2 ├── code.cpp └── notes.txt ├── lecture-084=Backtracking_day-3 ├── code.cpp └── notes.txt ├── lecture-085=Graphs_intro ├── code.cpp └── notes.txt ├── lecture-086=BFS_traversal ├── code.cpp └── notes.txt ├── lecture-087=DFS_traversal ├── code.cpp └── notes.txt ├── lecture-088=Cycle_detect_undirected_graph ├── code.cpp └── notes.txt ├── lecture-089=Cycle_detection_directed_graph ├── code.cpp └── notes.txt ├── lecture-090=Topological_sort(using-DFS) ├── code.cpp └── notes.txt ├── lecture-091=Topological_sort(using_Kahn's-algo) ├── code.cpp └── notes.txt ├── lecture-092=Cycle_detect_directed_graph_BFS ├── code.cpp └── notes.txt ├── lecture-093=Shortest_path_in_undirected_graphs ├── code.cpp └── notes.txt ├── lecture-094=Shortest_path_in_directed_acyclic_graphs ├── code.cpp └── notes.txt ├── lecture-095=Dijkstra's_algo ├── code.cpp └── notes.txt ├── lecture-096=Min_spanning_tree ├── code.cpp └── notes.txt ├── lecture-097=Kruskal's-algo_disjoint_set ├── code.cpp └── notes.txt ├── lecture-098=Bridges_in_graph ├── code.cpp └── notes.txt ├── lecture-099=Articulation_points_in_graphs ├── code.cpp └── notes.txt ├── lecture-100=Kosaraju's algo_for_strongly_connected_comp ├── code.cpp └── notes.txt ├── lecture-101=Bellman_ford_algo ├── code.cpp └── notes.txt ├── lecture-102=Intro_to_DP_memoization_tabulation ├── code.cpp └── notes.txt ├── lecture-103=Min_cost_climbing_stairs ├── code.cpp └── notes.txt ├── lecture-104=Min_number_of_coins ├── code.cpp └── notes.txt ├── lecture-105=Max_sum_of_non_adjacent_elements ├── code.cpp └── notes.txt ├── lecture-106=House_robbery_problem ├── code.cpp └── notes.txt ├── lecture-107=Cut_rod_intro_segments_of-x,y,z ├── code.cpp └── notes.txt ├── lecture-108=Count_derangements ├── code.cpp └── notes.txt ├── lecture-109=Painting_fence_algo ├── code.cpp └── notes.txt ├── lecture-110=0-1_knapsack_problem ├── code.cpp └── notes.txt ├── lecture-111=Combination_sum_IV_problem ├── code.cpp └── notes.txt ├── lecture-112=Perfect_squares_problem ├── code.cpp └── notes.txt ├── lecture-113=Min_cost_for_tickets ├── code.cpp └── notes.txt ├── lecture-114=Min_cost_for_tickets_part-2 ├── code.cpp └── notes.txt ├── lecture-115=Largest_square_area_in_matrix ├── code.cpp └── notes.txt ├── lecture-116=Min_score_triangulation_of_polygon ├── code.cpp └── notes.txt ├── lecture-117=Min_sideways_jump ├── code.cpp └── notes.txt ├── lecture-118=Reducing_dishes ├── code.cpp └── notes.txt ├── lecture-119=Longest_increasing_subsequence+Russian_doll ├── code.cpp └── notes.txt ├── lecture-120=Max_height_by_stacking_cuboid ├── code.cpp └── notes.txt ├── lecture-121=Pizza_with_3n_slices ├── code.cpp └── notes.txt ├── lecture-122=Number_of_dice_rolls_with_target_sum ├── code.cpp └── notes.txt ├── lecture-123=Partition_equal_subset_sum ├── code.cpp └── notes.txt ├── lecture-124=Min_swaps_to_make_subsequences_increasing ├── code.cpp └── notes.txt ├── lecture-125=Longest_arithmatic_subsequence ├── code.cpp └── notes.txt ├── lecture-126=Longest_AP_with_given_difference-d ├── code.cpp └── notes.txt ├── lecture-127=Unique_BST ├── code.cpp └── notes.txt ├── lecture-128=Guess_number_higher_or_lower ├── code.cpp └── notes.txt ├── lecture-129=Min_cost_tree_from_leaf_values ├── code.cpp └── notes.txt ├── lecture-130=Buy_and_sell_stock_part-1 ├── code.cpp └── notes.txt ├── lecture-131=Buy_and_sell_stock_part-2 ├── code.cpp └── notes.txt ├── lecture-132=Buy_and_sell_stock_part-3 ├── code.cpp └── notes.txt ├── lecture-133=Buy_and_sell_stock_part-4 ├── code.cpp └── notes.txt ├── lecture-134=Buy_and_sell_stock_part-5 ├── code.cpp └── notes.txt ├── lecture-135=Longest_common_subsequence ├── code.cpp └── notes.txt ├── lecture-136=Longest_palindromic_subsequence ├── code.cpp └── notes.txt ├── lecture-137=EDIT_distance ├── code.cpp └── notes.txt ├── lecture-138=Max_rectangle_with_1's ├── code.cpp └── notes.txt ├── lecture-139=Wildcard_pattern_matching ├── code.cpp └── notes.txt ├── lecture-140=Greedy_algo_one-shot ├── code.cpp └── notes.txt ├── lecture-141=Segment_Trees(Bonus) ├── code.cpp └── notes.txt ├── lecture-142=Fenwick_Trees(Bonus) ├── code.cpp └── notes.txt ├── lecture-143=Bitmasking(Bonus) ├── code.cpp └── notes.txt ├── lecture-144=Disjoint_Set(Bonus) ├── code.cpp └── notes.txt ├── lecture-145=Doubly_Ended_Queue(Bonus) ├── code.cpp └── notes.txt ├── lecture-146=Ordered_Set(Bonus) ├── code.cpp └── notes.txt ├── lecture-147=Priority_Queue(Bonus) ├── code.cpp └── notes.txt ├── lecture-69=BST_intro ├── code.cpp └── notes.txt └── mcq question screenshots ├── question1.png ├── question10.png ├── question11.png ├── question12.png ├── question13.png ├── question14.png ├── question15.png ├── question16.png ├── question17.png ├── question18.png ├── question19.png ├── question2.png ├── question20-explanation.png ├── question20.png ├── question21-explanation.png ├── question21.png ├── question22.png ├── question23.png ├── question24.png ├── question25.png ├── question26.png ├── question27.png ├── question28.png ├── question29.png ├── question3.png ├── question30.png ├── question4.png ├── question5.png ├── question6.png ├── question7.png ├── question8.png └── question9.png /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | lecture-014/code.exe 3 | -------------------------------------------------------------------------------- /Cheatsheets_and_notes/C++_Cheatsheet_CodeWithHarry.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/C++_Cheatsheet_CodeWithHarry.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_CompleteNotes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_CompleteNotes.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/1. Chapter-0 (Basics)/ds0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/1. Chapter-0 (Basics)/ds0.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/2. Time Complexity & Big O Notation/ds1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/2. Time Complexity & Big O Notation/ds1.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/3-Asymptotic_Notations/Asymptotic_Notations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/3-Asymptotic_Notations/Asymptotic_Notations.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/4-Best_Worst_Average/Best_Worst_Average.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/4-Best_Worst_Average/Best_Worst_Average.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/ADTs.one: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/ADTs.one -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/ADTs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/ADTs.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/Algorithms.one: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/Algorithms.one -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/Open Notebook.onetoc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/5-ADTs/Open Notebook.onetoc2 -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/6-ArrayOperations/Array_Operations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/6-ArrayOperations/Array_Operations.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/7-LinearVsBinary/LinearVsBinary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/7-LinearVsBinary/LinearVsBinary.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/1-LinkedLists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/1-LinkedLists.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/2-Linked_List_Deletion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/2-Linked_List_Deletion.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/3-Circular_Linked_Lists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/3-Circular_Linked_Lists.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/4-DoublyLinkedLists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/8-Linked Lists/4-DoublyLinkedLists.pdf -------------------------------------------------------------------------------- /Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/9-Stack/Introduction_To_Stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Cheatsheets_and_notes/DSA_TopicWise_Notes/DSA_TopicWise_Notes/9-Stack/Introduction_To_Stack.pdf -------------------------------------------------------------------------------- /Course_outline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/Course_outline.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Sarthak Sachdev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README-image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/README-image.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Love Babbar DSA Playlist - Full Code and Notes](https://www.youtube.com/playlist?list=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA) 2 | 3 | Welcome to the Love Babbar DSA Playlist repository! Here, you'll find comprehensive notes, code solutions, and optimizations for all the homework and practice questions from the renowned Love Babbar DSA course. 4 | 5 | Thank you for visiting this repository. All the resources provided here are completely free of cost. Please refer to the license file for terms and conditions regarding the use, redistribution, and modification of the content. 6 | 7 | ### Apart from the usual course videos, I have added more bonus notes and code of more complex topics that are also considered necessary for upscaling in competitive programming along with some other resources provided at the top of the repository, youtube video links that were referred to make these notes will be provided in the bonus folders themselves😇😇 8 | 9 | ![Love-Babbar DSA course](README-image.jpg) 10 | 11 | ## Overview 12 | 13 | This repository contains everything you need to master data structures and algorithms through Love Babbar's DSA playlist. Whether you're a beginner or an experienced programmer, these resources will aid in enhancing your skills. 14 | 15 | ## Getting Started 16 | 17 | To get started with the Love Babbar DSA Playlist, follow these steps: 18 | 19 | 1. Clone this repository to your local machine. 20 | 2. Navigate to the respective folder for the topic or question you want to explore. 21 | 3. Explore the code, notes, and optimized solutions provided. 22 | 23 | ## Features 24 | 25 | - Detailed explanations for each algorithm and data structure covered in the playlist. 26 | - Optimized solutions to practice questions and homework assignments. 27 | - Code snippets and implementation examples for better understanding. 28 | 29 | ## Contribution 30 | 31 | Contributions to this repository are welcome! If you have any improvements, corrections, or additional solutions to share, feel free to open a pull request. 32 | 33 | ## Support 34 | 35 | If you encounter any issues or have questions regarding the content, feel free to open an issue in the repository. We're here to help! 36 | 37 | ## License 38 | 39 | This repository is licensed under the [MIT License](LICENSE). Feel free to use the content for personal or educational purposes. 40 | 41 | --- 42 | 43 | We hope you find this repository helpful in your journey of mastering data structures and algorithms. Happy coding! 44 | -------------------------------------------------------------------------------- /competitive-programming-resources/awesome-competitive-programming-master/.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2 4 | before_script: 5 | - gem install awesome_bot 6 | script: 7 | - awesome_bot README.md --allow-dupe --white-list codeforces.com,goo.gl,vjudge.net,travis-ci.org,quora.com,i.creativecommons.org,csdn.net,amazon.com,amazon.cn,icpc,codechef,tcframe,amzn.to,bnuoj.com 8 | -------------------------------------------------------------------------------- /competitive-programming-resources/awesome-competitive-programming-master/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Awesome Competitive Programming [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 2 | 3 | ## Contributing Guidelines 4 | 5 | ### Principle 6 | The guiding principle for this list is to connect more people to information. 7 | So thank you for paying an interest in this page :) 8 | 9 | Please just note that this is a **curated** list which means it's not a complete catalogue of everything. 10 | 11 | ### TODOs 12 | 1. Better descriptions 13 | 2. More great resources from other regions 14 | 3. Social media around programming competitions (eg. ACM-ICPC) 15 | 4. A short reference sheet 16 | 5. Anything you can think of! 17 | 18 | ### Submission 19 | 1. For new items or modifications, submit a pull request here ([learn how to](https://help.github.com/articles/using-pull-requests/)). 20 | 2. For dead links or suggestions, [create an issue](https://github.com/lnishan/awesome-competitive-programming/issues/new). 21 | 3. Or, you can simply [message me on Codeforces](http://codeforces.com/usertalk?other=lnishan). 22 | 23 | ### Rules 24 | 1. Please do not submit confidential resources (eg. handouts from closed training camps). 25 | 2. To add a new item or make modifications to the list, make sure you state your reasons (ie. Why is it awesome?). 26 | -------------------------------------------------------------------------------- /competitive-programming-resources/awesome-competitive-programming-master/README.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/competitive-programming-resources/awesome-competitive-programming-master/README.pdf -------------------------------------------------------------------------------- /competitive-programming-resources/awesome-competitive-programming-master/_config.yml: -------------------------------------------------------------------------------- 1 | title: Awesome-competitive-programming 2 | description: ":gem: A curated list of awesome Competitive Programming, Algorithm and Data Structure resources" 3 | google_analytics: 4 | show_downloads: true 5 | theme: jekyll-theme-cayman 6 | 7 | gems: 8 | - jekyll-mentions 9 | -------------------------------------------------------------------------------- /contests_solutions/1st-contest/Apple_shop_with_ninja.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | long long appleAndCoupon(int n, int m, vector arr) 7 | { 8 | sort(arr.begin(), arr.end()); 9 | long long sum = 0; 10 | for (int i = 0; i < arr.size(); i++) 11 | { 12 | sum += arr[i]; 13 | } 14 | sum -= arr[arr.size() - m]; 15 | return sum; 16 | } -------------------------------------------------------------------------------- /contests_solutions/1st-contest/Draw_the_diamond.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void printTheDiamond(int r, int c, int s) 4 | { 5 | for (int i = 0; i < r; i++) 6 | { 7 | for (int j = 0; j < s; j++) 8 | { 9 | for (int k = 0; k < c; k++) 10 | { 11 | for (int l = 0; l < (s - j - 1); l++) 12 | { 13 | cout << "e"; 14 | } 15 | cout << "/"; 16 | for (int m = 0; m < j; m++) 17 | { 18 | cout << "oo"; 19 | } 20 | cout << "\\"; 21 | for (int l = 0; l < (s - j - 1); l++) 22 | { 23 | cout << "e"; 24 | } 25 | } 26 | cout << endl; 27 | } 28 | for (int j = 0; j < s; j++) 29 | { 30 | 31 | for (int k = 0; k < c; k++) 32 | { 33 | for (int m = j; m > 0; m--) 34 | { 35 | cout << "e"; 36 | } 37 | cout << "\\"; 38 | for (int l = j + 1; l < s; l++) 39 | { 40 | cout << "oo"; 41 | } 42 | cout << "/"; 43 | for (int m = j; m > 0; m--) 44 | { 45 | cout << "e"; 46 | } 47 | } 48 | cout << endl; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /contests_solutions/1st-contest/Maximize_X.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int findMaxX(int n, vector> &arr, int B) 8 | { 9 | int size=arr.size(); 10 | int x=1; 11 | int row=arr.size(); 12 | int sum=0; 13 | int i=0; 14 | int j=0; 15 | for(i=0;iy; 20 | for(i=0;i=0) 31 | { 32 | if(sum<=B) 33 | { 34 | return j; 35 | } 36 | else 37 | { 38 | sum=sum-y[i]; 39 | j=y[i]-1; 40 | i--; 41 | } 42 | } 43 | return y[0]; 44 | } -------------------------------------------------------------------------------- /contests_solutions/1st-contest/Three_way_split.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | long long threeWaySplit(int n, vector arr) 6 | { 7 | long long ans = 0; 8 | long long start = 0; 9 | long long end = n - 1; 10 | long long s1 = arr[start]; 11 | long long s2 = arr[end]; 12 | 13 | while (start < end) 14 | { 15 | 16 | if (s1 == s2) 17 | { 18 | ans = s1; 19 | 20 | start++; 21 | end--; 22 | 23 | s1 += arr[start]; 24 | s2 += arr[end]; 25 | } 26 | 27 | else if (s1 < s2) 28 | { 29 | 30 | start++; 31 | 32 | s1 += arr[start]; 33 | } 34 | 35 | else 36 | { 37 | 38 | end--; 39 | 40 | s2 += arr[end]; 41 | } 42 | } 43 | 44 | return ans; 45 | } -------------------------------------------------------------------------------- /contests_solutions/2nd-contest/1-Class_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int classTest(int n, vector &a, int k) { 7 | std::sort(a.begin(), a.end()); 8 | return a[n-k]; 9 | } -------------------------------------------------------------------------------- /contests_solutions/2nd-contest/2-Binary_shopping.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string binaryShopping(string S, int P) 5 | { 6 | int count = 0; 7 | for (int i = S.size() - 1; i >= 0; i--) 8 | { 9 | if (count < 2) 10 | { 11 | if (S[i] == '1') 12 | { 13 | count++; 14 | S[i] = '0'; 15 | } 16 | } 17 | } 18 | if (count == 1) 19 | { 20 | S[0] = '1'; 21 | } 22 | return S; 23 | } -------------------------------------------------------------------------------- /contests_solutions/2nd-contest/3-Longest_subarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | vector bitwiseAnd(int n, int q, vector arr, vector queries) 6 | { 7 | vector sol; 8 | int i = 0; 9 | while (i < q) 10 | { 11 | int temp = queries[i]; 12 | int st = arr[0]; 13 | int j = 1; 14 | int store = 0; 15 | if (st >= temp) 16 | { 17 | store = 1; 18 | } 19 | while (j < n) 20 | { 21 | if ((st & arr[j]) >= temp) 22 | { 23 | store = j + 1; 24 | st = st & arr[j]; 25 | if (j == n - 1) 26 | { 27 | sol.push_back(store); 28 | } 29 | j++; 30 | } 31 | else 32 | { 33 | sol.push_back(store); 34 | break; 35 | } 36 | } 37 | i++; 38 | } 39 | return sol; 40 | } -------------------------------------------------------------------------------- /contests_solutions/2nd-contest/4-Light_up_street.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int LightUptheStreet(int n, int m, int k, vector check) 6 | { 7 | int last = 0; 8 | int next = 0; 9 | int count = 1; 10 | int i = 0; 11 | bool c = 1; 12 | if ((check[0] - k <= 1) && (check[m - 1] + k >= n)) 13 | { 14 | while (i < m) 15 | { 16 | if ((check[i] - k <= 1) && (check[i] + k >= n)) 17 | { 18 | c = 0; 19 | break; 20 | } 21 | if (i <= m - 2) 22 | { 23 | if (check[i + 1] - check[i] - 1 > 2 * k) 24 | { 25 | return -1; 26 | break; 27 | } 28 | } 29 | if (i == m - 1) 30 | { 31 | if (last > next + 1) 32 | { 33 | count++; 34 | c = 0; 35 | } 36 | } 37 | if (check[i] + k >= n) 38 | { 39 | count++; 40 | c = 0; 41 | break; 42 | } 43 | if (check[i] - k <= 1) 44 | { 45 | last = check[i + 1] - k; 46 | next = check[i] + k; 47 | i++; 48 | } 49 | else if (last <= next + 1) 50 | { 51 | i++; 52 | last = check[i] - k; 53 | } 54 | else if (last > next + 1) 55 | { 56 | i--; 57 | last = check[i + 1] - k; 58 | next = check[i] + k; 59 | count++; 60 | c = 0; 61 | } 62 | } 63 | if (c) 64 | { 65 | return -1; 66 | } 67 | else 68 | { 69 | return count; 70 | } 71 | } 72 | else 73 | { 74 | return -1; 75 | } 76 | } -------------------------------------------------------------------------------- /lecture-001=Flowcharts/Lecture1-handwritten.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-001=Flowcharts/Lecture1-handwritten.pdf -------------------------------------------------------------------------------- /lecture-001=Flowcharts/Lecture1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-001=Flowcharts/Lecture1.pdf -------------------------------------------------------------------------------- /lecture-001=Flowcharts/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we discussed the introduction to programming, how programming languages help us communicate what we want to tell the computer to do and how there are different programming languages for different tasks. 2 | 3 | There are compilers in computers who compile and convert programming language high level syntax to machine understandable binary code and help us get the job done. 4 | 5 | Then we started with the basics of programming by learning and implementing the concept of flowcharts and how they can be useful to understand the workflow of a program. 6 | 7 | Then lastly we learnt about various basic concepts like loops, operators like arithmatic operators and conditionals. -------------------------------------------------------------------------------- /lecture-002=First_program/Lecture2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-002=First_program/Lecture2.pdf -------------------------------------------------------------------------------- /lecture-002=First_program/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | cout << "Namaste Duniya :-)" << endl; 7 | 8 | int a = 12; // 4 bytes 9 | bool b = false; // 1 byte 10 | char c = 'a'; // 1 byte 11 | double d = 3.1415926535; // 8 bytes 12 | float f = 323.34; // 4 bytes 13 | string s = "Love Babbar"; // sizeof works differently for strings as it depends on various other stuff in this case 14 | // there can be other types of datatypes used too like long double, long long, unsigned int, __int128 and so on 15 | 16 | cout << sizeof(a) << " " << sizeof(b) << " " << sizeof(c) << " " << sizeof(d) << " " << sizeof(f) << " " << sizeof(s) << endl; 17 | 18 | int e = 23; 19 | 20 | cout << a / e << " " << (float)a / e << endl; // advantage of typecasting 21 | cout << 2/a << " " << 2.0/a < 2 | using namespace std; 3 | // Homework questions- solution 4 | // Question-1 5 | void FirstQuestion() 6 | { 7 | int a = 9; 8 | if (a == 9) 9 | cout << "NINEY" 10 | << "\n"; 11 | 12 | if (a > 0) 13 | cout << "POSITIVE" 14 | << "\n"; 15 | 16 | else 17 | cout << "NEGATIVE" 18 | << "\n"; // output= NINEY POSITIVE 19 | } 20 | 21 | // Question-2 22 | void SecondQuestion() 23 | { 24 | int a = 2; 25 | int b = a + 1; 26 | 27 | if ((a = 3) == b) 28 | cout << a 29 | << "\n"; 30 | 31 | else 32 | cout << a + 3 33 | << "\n"; // output= 3 34 | } 35 | 36 | // Question-3 37 | void ThirdQuestion() 38 | { 39 | int a = 24; 40 | 41 | if (a > 20) 42 | cout << "Love" 43 | << "\n"; 44 | 45 | else if (a == 24) 46 | cout << "Lovely" 47 | << "\n"; 48 | 49 | else 50 | cout << "Not lovely" 51 | << "\n"; 52 | 53 | cout << a 54 | << "\n"; // output= Love 55 | } 56 | 57 | // Question-4 58 | void FourthQuestion(char ch) 59 | { 60 | if (ch >= 'a' && ch <= 'z') 61 | cout << "Lowecase\n"; 62 | 63 | else if (ch >= 'A' && ch <= 'Z') 64 | cout << "Uppercase\n"; 65 | 66 | else if (ch >= 49 && ch <= 57) 67 | cout << "Number\n"; 68 | 69 | else 70 | cout << "Enter valid input\n"; 71 | } 72 | 73 | int main(int argc, char const *argv[]) 74 | { 75 | FirstQuestion(); 76 | SecondQuestion(); 77 | ThirdQuestion(); 78 | FourthQuestion(';'); 79 | return 0; 80 | } -------------------------------------------------------------------------------- /lecture-003=Conditionals_&_loops/lec-3_notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-003=Conditionals_&_loops/lec-3_notes.pdf -------------------------------------------------------------------------------- /lecture-003=Conditionals_&_loops/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we started off by learning C++ syntax about how we take input and output in a compiler. 2 | 3 | One new thing we learnt here was that the compiler does not read space, tab and break-line(enter) characters into the input but if we are taking input of a string where taking the input of space is important, then we will have to use cin.get(). 4 | 5 | If we don't know how many input there are going to be, we can use a while loop as follows- while(cin>>x){} 6 | 7 | Then we went on to learn about conditionals and how they are used. 8 | 9 | After that we udnerstood while loops and their significance in code. We also learned about its implementation by writing a few basic programs like finding sum till n. 10 | 11 | Then lastly we tried implementing few basic pattern problems using nested loops and rest of the pattern problems were done in the next lecture. 12 | 13 | Let's delve into the differences between the two types of loops (for(auto i: container) and for(int i = 0...i++)) considering various data structures and algorithms: 14 | 15 | for(auto i: container) (Range-based for loop): 16 | 17 | Simplicity: This type of loop provides a more concise and readable syntax, especially when iterating over elements in a container. 18 | Ease of Use: It automatically handles the iteration over the entire container without needing to manage indices or iterators explicitly. 19 | Type Inference: The type of the loop variable i is automatically inferred based on the elements of the container, reducing the chance of errors related to mismatched types. 20 | Convenience: It's particularly useful for containers like vectors, arrays, lists, and sets, where the iteration order matches the order of elements in the container. 21 | for(int i = 0...i++) (Traditional for loop): 22 | 23 | Explicit Control: This loop provides explicit control over the iteration process, allowing customization of the iteration variable, initial value, condition, and increment/decrement. 24 | Flexibility: It's suitable for scenarios where you need to access elements based on their indices or perform complex iteration patterns not covered by a simple range-based loop. 25 | Index-based Access: Ideal for data structures like arrays and vectors where direct access to elements by index is efficient and necessary. 26 | Performance Considerations: Depending on the data structure and operation, index-based iteration may offer better performance due to direct access to elements, especially when modifying elements in-place or performing complex computations within the loop. 27 | Considerations for Different Data Structures: 28 | 29 | Vectors and Arrays: 30 | 31 | Range-based loops are convenient for iterating over elements sequentially. 32 | Traditional for loops might be preferred when you need to access elements by index or perform complex iteration patterns. 33 | Linked Lists: 34 | 35 | Traditional for loops are often used to traverse linked lists because they typically involve iterating through nodes using pointers. 36 | Sets and Maps: 37 | 38 | Range-based loops are suitable for iterating over elements in sorted order. 39 | Traditional for loops may be used for specific purposes like accessing elements by index or performing iteration based on custom conditions. 40 | Considerations for Different Algorithms: 41 | 42 | Searching Algorithms: 43 | 44 | Range-based loops can simplify the code for linear search algorithms where you iterate over elements sequentially. 45 | Traditional for loops might be necessary for binary search algorithms that require index-based access to elements. 46 | Sorting Algorithms: 47 | 48 | Both types of loops can be used, but range-based loops are often favored for simplicity when iterating over sorted containers. 49 | Graph Algorithms: 50 | 51 | Traditional for loops are common for graph traversal algorithms like Depth-First Search (DFS) and Breadth-First Search (BFS) where explicit control over iteration is required. 52 | In summary, the choice between using a range-based for loop and a traditional for loop depends on factors such as code readability, simplicity, performance considerations, and specific requirements of the data structure or algorithm being implemented. Both types of loops have their advantages and are suitable for different scenarios. -------------------------------------------------------------------------------- /lecture-004=Pattern_problems/Lecture4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-004=Pattern_problems/Lecture4.pdf -------------------------------------------------------------------------------- /lecture-004=Pattern_problems/Solving_pattern_questions(Part-2).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-004=Pattern_problems/Solving_pattern_questions(Part-2).pdf -------------------------------------------------------------------------------- /lecture-004=Pattern_problems/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // Homework questions 4 | // Question-1 5 | 6 | void FirstQuestion() 7 | { 8 | int count = 1; 9 | int n; 10 | cin >> n; 11 | for (int i = 0; i < n; i++) 12 | { 13 | for (int j = 0; j <= i; j++) 14 | { 15 | cout << count << " "; 16 | count++; 17 | } 18 | cout << endl; 19 | } 20 | } 21 | 22 | // Question-2 23 | void SecondQuestion() 24 | { 25 | int n; 26 | cin >> n; 27 | int row = 1; 28 | while (row <= n) 29 | { 30 | int col = 1; 31 | while (col <= row) 32 | { 33 | cout << col + row - 1 << " "; 34 | col++; 35 | } 36 | cout << "\n"; 37 | row++; 38 | } 39 | } 40 | 41 | // Question-3 42 | void ThirdQuestion() 43 | { 44 | int n; 45 | cin >> n; 46 | for (int i = 0; i < n; i++) 47 | { 48 | char ch = 'A'; 49 | for (int j = 0; j < n; j++) 50 | { 51 | cout << ch << " "; 52 | ch++; 53 | } 54 | cout << "\n"; 55 | } 56 | } 57 | 58 | // Question-4 59 | void FourthQuestion() 60 | { 61 | int n; 62 | cin >> n; 63 | char ch = 'A'; 64 | for (int i = 0; i < n; i++) 65 | { 66 | for (int j = 0; j < n; j++) 67 | { 68 | cout << ch << " "; 69 | ch++; 70 | } 71 | cout << endl; 72 | } 73 | } 74 | 75 | // Question-5 76 | void FifthQuestion() 77 | { 78 | int n; 79 | cin >> n; 80 | char ch = 'A' + n; 81 | int row = 0; 82 | while (++row <= n) 83 | { 84 | char temp = ch - row; 85 | int col = 0; 86 | while (++col <= row) 87 | { 88 | cout << temp << " "; 89 | temp++; 90 | } 91 | cout << "\n"; 92 | } 93 | } 94 | 95 | // Question-6 96 | void SixthQuestion() 97 | { 98 | int n; 99 | cin >> n; 100 | int row = 0; 101 | while (++row <= n) 102 | { 103 | int col = n + 1; 104 | 105 | while (--col >= row) 106 | cout << "* "; 107 | 108 | cout << "\n"; 109 | } 110 | } 111 | 112 | // Question-7 113 | void SeventhQuestion() 114 | { 115 | int n; 116 | cin >> n; 117 | int row = 0; 118 | while (++row <= n) 119 | { 120 | int col = n + 1; 121 | 122 | int temp = 0; 123 | 124 | while (++temp != row) 125 | cout << " "; 126 | 127 | while (--col >= row) 128 | cout << "* "; 129 | 130 | cout << "\n"; 131 | } 132 | } 133 | 134 | // Question-8 135 | void EighthQuestion() 136 | { 137 | int n; 138 | cin >> n; 139 | for (int i = 1; i <= n; i++) 140 | { 141 | int temp = 1; 142 | while (temp++ < i) 143 | cout << " "; 144 | 145 | int temp2 = i; 146 | for (int j = i; j <= n; j++) 147 | { 148 | cout << temp2 << " "; 149 | } 150 | cout << "\n"; 151 | } 152 | 153 | for (int i = 1; i <= n; i++) 154 | { 155 | int temp = n; 156 | while (temp-- > i) 157 | cout << " "; 158 | 159 | int temp2 = i; 160 | for (int j = 1; j <= i; j++) 161 | { 162 | cout << temp2 << " "; 163 | } 164 | cout << "\n"; 165 | } 166 | } 167 | 168 | // Question-9 169 | void NinthQuestion() 170 | { 171 | int n; 172 | cin >> n; 173 | for (int i = 0; i < n; i++) 174 | { 175 | for (int j = 0; j < n - i; j++) 176 | { 177 | cout << j + 1 << " "; 178 | } 179 | 180 | for (int k = 0; k < 2 * i; k++) 181 | { 182 | cout << "*" 183 | << " "; 184 | } 185 | 186 | for (int l = 0; l < n - i; l++) 187 | { 188 | cout << n - l - i << " "; 189 | } 190 | cout << "\n"; 191 | } 192 | } 193 | 194 | int main(int argc, char const *argv[]) 195 | { 196 | FirstQuestion(); 197 | SecondQuestion(); 198 | ThirdQuestion(); 199 | FourthQuestion(); 200 | FifthQuestion(); 201 | SixthQuestion(); 202 | SeventhQuestion(); 203 | EighthQuestion(); 204 | NinthQuestion(); 205 | return 0; 206 | } -------------------------------------------------------------------------------- /lecture-004=Pattern_problems/notes.txt: -------------------------------------------------------------------------------- 1 | This lecture was the continuition lecture of lec-3 pattern problems in which we solved basic pattern problems using nested loops but here we tried approaching more complex patterns and solved them. -------------------------------------------------------------------------------- /lecture-005=Bitwise_&_operator_precedence/Bitwise Operators, For Loops, Operator Precedence.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-005=Bitwise_&_operator_precedence/Bitwise Operators, For Loops, Operator Precedence.pdf -------------------------------------------------------------------------------- /lecture-005=Bitwise_&_operator_precedence/Lecture5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-005=Bitwise_&_operator_precedence/Lecture5.pdf -------------------------------------------------------------------------------- /lecture-005=Bitwise_&_operator_precedence/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Homework questions 5 | // Question-1 6 | 7 | void FirstQuestion() 8 | { 9 | int a, b = 1; 10 | a = 10; 11 | if (++a) 12 | cout << b << "\n"; 13 | 14 | else 15 | cout << ++b << "\n"; // Output= 1 16 | } 17 | 18 | void SecondQuestion() 19 | { 20 | int a = 1; 21 | int b = 2; 22 | 23 | if (a-- > 0 && ++b > 2) 24 | cout << "Stage1 - Inside If " 25 | << "\n"; 26 | 27 | else 28 | cout << "Stage2 - Inside else " // If the if condition was not satisfied, will a and b still change? 29 | << "\n"; // The answer to above question is- Yes they will due to higher operator precendence of increment and decrement operators 30 | 31 | cout << a << " " << b << endl; // Output= Stage1 - Inside If 0 3 32 | } 33 | 34 | void ThirdQuestion() 35 | { 36 | int a = 1; 37 | int b = 2; 38 | 39 | if (a-- > 0 || ++b > 2) 40 | cout << "Stage1 - Inside If " // Understand more such exceptions, like here ++b command didn't even get executed as a-- condition was true 41 | << "\n"; 42 | 43 | else 44 | cout << "Stage2 - Inside else " 45 | << "\n"; 46 | 47 | cout << a << " " << b << endl; // Output= Stage1 - Inside If 0 2 48 | } 49 | 50 | void FourthQuestion() 51 | { 52 | int number = 3; 53 | cout << (25 * (++number)) << "\n"; // output= 100 54 | } 55 | 56 | void FifthQuestion() 57 | { 58 | int a = 1; 59 | int b = a++; 60 | int c = ++a; 61 | cout << b << "\n"; 62 | cout << c << "\n"; // Output= 1 3 63 | } 64 | 65 | void SixthQuestion() 66 | { 67 | for (int i = 0; i <= 5; i++) 68 | { 69 | cout << i << " "; 70 | i++; 71 | } 72 | // Output= 0 2 4 73 | } 74 | 75 | void SeventhQuestion() 76 | { 77 | for (int i = 0; i <= 5; i--) 78 | { 79 | cout << i << " "; 80 | i++; 81 | } 82 | // Output= {infinite loop} 83 | } 84 | 85 | void EighthQuestion() 86 | { 87 | for (int i = 0; i <= 15; i += 2) 88 | { 89 | cout << i << " "; 90 | if (i & 1) 91 | continue; 92 | 93 | i++; 94 | } 95 | // Output= 0 3 5 7 9 11 13 15 96 | } 97 | 98 | void NinthQuestion() 99 | { 100 | for (int i = 0; i < 5; i++) 101 | { 102 | for (int j = i; j <= 5; j++) 103 | { 104 | cout << i << " " << j << endl; 105 | } 106 | } 107 | // Output= 0 0 0 1 0 2 0 3 0 4 0 5 1 1 1 2 1 3 1 4 1 5 2 2 2 3 2 4 2 5 3 3 3 4 3 5 4 4 4 5 108 | } 109 | 110 | void TenthQuestion() 111 | { 112 | for (int i = 0; i < 5; i++) 113 | { 114 | for (int j = i; j <= 5; j++) 115 | { 116 | if (i + j == 10) 117 | break; 118 | 119 | cout << i << " " << j << endl; 120 | } 121 | } 122 | // Output= 0 0 0 1 0 2 0 3 0 4 0 5 1 1 1 2 1 3 1 4 1 5 2 2 2 3 2 4 2 5 3 3 3 4 3 5 4 4 4 5 123 | } 124 | 125 | int subtractProductAndSum(int n) 126 | { 127 | int product = 1; 128 | int sum = 0; 129 | while(n>0) 130 | { 131 | int digit = n % 10; 132 | product *= digit; 133 | sum += digit; 134 | n /= 10; 135 | } 136 | return product-sum; 137 | } 138 | 139 | int hammingWeight(uint32_t n) 140 | { 141 | int setBits = 0; 142 | while(n>0) 143 | { 144 | if(n&1) 145 | setBits++; 146 | 147 | n>>1; 148 | } 149 | return setBits; 150 | } 151 | 152 | int main(int argc, char const *argv[]) 153 | { 154 | FirstQuestion(); 155 | SecondQuestion(); 156 | ThirdQuestion(); 157 | FourthQuestion(); 158 | FifthQuestion(); 159 | SixthQuestion(); 160 | SeventhQuestion(); 161 | EighthQuestion(); 162 | NinthQuestion(); 163 | TenthQuestion(); 164 | return 0; 165 | } -------------------------------------------------------------------------------- /lecture-005=Bitwise_&_operator_precedence/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture, we started off by learning about bitwise operators. 2 | 3 | Under bitwise operators we read about 4 bitwise operators, which are, & | ~ ^ 4 | 5 | & operator(AND operator)- This operator gives true only when both bits are 1(both are true) and thus is often used for cases where 2 conditions have to be true for execution of certain piece of code. 6 | 7 | | operator(OR operator)- This operator gives false only when both bits are 0(both are false) and thus is often used for cases where any one of 2 conditions have to be true for execution of certain piece of code. 8 | 9 | ~ operator(NOT operator)- This operator reverse the bit to 0 if it was 1, and makes it 1 if it was 0. For any integer, ~ of that integer is calculated by finding its 2's compliment(two's complement of an integer is calculated by first reversing all its bits. If the original integer's last bit is 1, the result is negated. To obtain the final representation for printing, reverse all the bits again and add 1, along with the negative sign if the integer was negated earlier). 10 | 11 | ^ operator(XOR operator)- This operator only gives 0(false) when the 2 values are equal, and thus is often used to detect duplicate values. 12 | 13 | Then we studied about 2 more operators- left and right shift operators. 14 | 15 | Left-shift operator- When we do left shift operator, we move all set bits to one place left and add a 0(this addition of digit is called padding and is always 0 in case of this operator) at the end of the number, and this can be used to find the double of a number as by doing one left shift we are moving each bit to left so it is similar to multiplying number by 2. 16 | 17 | Right-shift operator- When we do right shift operator, we move all set bits to one place right and add a 0 at the start of the number, and this can be used to find the number divided by 2 as by doing one left shift we are moving each bit to left so it is similar to multiplying number by 2. 18 | 19 | The bits operations for integers are preferred than normal code because they are much faster. 20 | 21 | NOTE: In the case of edge cases, left shift operator might give wrong value as if the number is too big, the second last bit will be moved to last bit place and make the resultant number distorted than original value and negative. Similarly, we cannot use right-shift operator on a negative number as it will return a huge number. Also we cannot perform left-shift either on a negative number. 22 | 23 | NOTE2: When you perform a right shift operation on a binary number and the rightmost bit (the least significant bit) is 1, the behavior depends on the programming language and the specific type of right shift being used: arithmetic right shift or logical right shift. 24 | 25 | Logical Right Shift: 26 | In a logical right shift, the vacant bit positions on the left are filled with zeros. 27 | For example, if you have the binary number 1011 and you perform a logical right shift by one position, you get 0101. 28 | 29 | Arithmetic Right Shift: 30 | In an arithmetic right shift, the vacant bit positions on the left are filled with the value of the sign bit (the leftmost bit). 31 | If the original number is positive (sign bit is 0), then the vacant positions are filled with zeros. 32 | If the original number is negative (sign bit is 1), then the vacant positions are filled with ones. 33 | For example, if you have the binary number 1011 (which is -5 in decimal, assuming two's complement representation) and you perform an arithmetic right shift by one position, you get 1101. 34 | 35 | It's important to note that the behavior may vary depending on the programming language and the data type used for the right shift operation. Most languages provide both logical and arithmetic right shift operators, and the default behavior might be different. 36 | 37 | NOTE: In performing left-shift or right-shift on a negative number, the padding is compiler dependent and may not always be 0. 38 | 39 | Later, we studied some more topics like pre-increment and post-increment operators and pre-decrement and post-decrement operators. 40 | 41 | After that we studied about a new type of loop that is for loop and understood its syntax. 42 | Then using for loop we solved few basic problems like sum from 1 to n, fibonacci series from 1 to n and if n is a prime number. 43 | 44 | After that we learnt about break and continue keyword also. 45 | 46 | Then we learned about block and global scope of variables in conditionals, loops and functions. 47 | 48 | Lastly we solved some basic LeetCode problems about topics discussed in this lecture and rest of the questions will be taken up in next video. -------------------------------------------------------------------------------- /lecture-006=Binary_&_decimal_num_system/Decimal and Binary System.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-006=Binary_&_decimal_num_system/Decimal and Binary System.pdf -------------------------------------------------------------------------------- /lecture-006=Binary_&_decimal_num_system/Lecture6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-006=Binary_&_decimal_num_system/Lecture6.pdf -------------------------------------------------------------------------------- /lecture-006=Binary_&_decimal_num_system/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // string ITOS(int n) 5 | // { 6 | // if (n == 0) 7 | // return "0"; 8 | 9 | // std::string result = ""; 10 | 11 | // while (n > 0) 12 | // { 13 | // char digit = '0' + n % 10; 14 | // result = digit + result; 15 | // n /= 10; 16 | // } 17 | 18 | // return result; 19 | // } 20 | 21 | // int STOI(string str) 22 | // { 23 | // int result = 0; 24 | // for (int i = 0; i < str.length(); i++) 25 | // { 26 | // char c = str[i]; 27 | // if ('0' <= c && '9' >= c) 28 | // result = result * 10 + (c - '0'); 29 | // } 30 | // return result; 31 | // } 32 | 33 | string decimalToBinary(int n) 34 | { 35 | string result = ""; 36 | while (n > 0) 37 | { 38 | if (n & 1) 39 | result += "1"; 40 | 41 | n >> 1; 42 | } 43 | return result; 44 | } 45 | 46 | int binaryToDecimal(string str) 47 | { 48 | int result = 0; 49 | for (int i = str.length() - 1; i >= 0; i--) 50 | { 51 | if (str[i] == '1') 52 | result |= 1 << (str.length() - 1 - i); 53 | } 54 | return result; 55 | } 56 | 57 | int main(int argc, char const *argv[]) 58 | { 59 | int n; 60 | cin >> n; 61 | string bin = decimalToBinary(n); 62 | cout << bin << endl; 63 | if (n == binaryToDecimal(bin)) 64 | cout << binaryToDecimal(bin) << endl; 65 | return 0; 66 | } -------------------------------------------------------------------------------- /lecture-006=Binary_&_decimal_num_system/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture, we studied more about memory allocation. We understood in depth about how integers are stored in binary system and how we can find the binary representation of a number or find the number from its binary representation in a program. 2 | 3 | Later on we inplemented the same in our IDE. 4 | 5 | Then we also learned how to change a negative decimal representation of a number to binary and vice versa. This can be done by utilizing a method called Two's Complement. Two's Complement is a binary representation scheme used to represent signed integers in a way that allows for easy addition and subtraction. To convert a negative decimal representation to binary using Two's Complement, follow these steps: 6 | 7 | Convert the Absolute Value to Binary: Begin by converting the absolute value of the negative decimal number to binary using the standard binary conversion method. 8 | 9 | Pad with Zeros: Ensure that the binary representation has the desired number of bits. If the absolute value requires fewer bits than the chosen bit length, pad the left side with zeros. 10 | 11 | Invert the Bits: Flip all the bits in the binary representation. Change 0s to 1s and vice versa. 12 | 13 | Add 1: Add 1 to the inverted binary representation. 14 | 15 | The resulting binary representation is the Two's Complement of the original negative decimal number. 16 | 17 | For example, let's convert -7 to an 8-bit Two's Complement binary representation: 18 | 19 | The absolute value of 7 in binary is 0111. 20 | Since we are using 8 bits, no padding is needed. 21 | Inverting the bits gives 1000. 22 | Adding 1 gives the final Two's Complement representation: 1001. 23 | Conversely, to convert a Two's Complement binary representation back to a negative decimal number, reverse the process: 24 | 25 | Check the Most Significant Bit (MSB): If the leftmost bit is 1, the number is negative. 26 | 27 | Invert the Bits: Flip all the bits. 28 | 29 | Convert to Decimal: Convert the inverted binary representation to decimal. 30 | 31 | Add a Negative Sign: Add a negative sign to the decimal result. 32 | 33 | Continuing with the example, if we have the 8-bit Two's Complement representation 1001: 34 | 35 | The MSB is 1, indicating a negative number. 36 | Inverting the bits gives 0110. 37 | Converting 0110 to decimal gives 6. 38 | Adding a negative sign results in -6, which is the original negative decimal number. -------------------------------------------------------------------------------- /lecture-007=Leetcode_session/Lecture7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-007=Leetcode_session/Lecture7.pdf -------------------------------------------------------------------------------- /lecture-007=Leetcode_session/LeetCode Problem Solving Session.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-007=Leetcode_session/LeetCode Problem Solving Session.pdf -------------------------------------------------------------------------------- /lecture-007=Leetcode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Solution 5 | { 6 | public: 7 | int reverse(int x) 8 | { 9 | int ans = 0; 10 | bool negativeNum = false; 11 | 12 | if (x < 0) 13 | { 14 | negativeNum = true; 15 | x = abs(x); 16 | } 17 | 18 | while (x > 0) 19 | { 20 | int lastDigit = x % 10; 21 | 22 | // Check for overflow and underflow 23 | if (ans > INT_MAX / 10 || (ans == INT_MAX / 10 && lastDigit > 7)) 24 | { 25 | return 0; 26 | } 27 | if (-1 * ans < INT_MIN / 10 || (-1 * ans == INT_MIN / 10 && lastDigit < -8)) 28 | { 29 | return 0; 30 | } 31 | 32 | ans = ans * 10 + lastDigit; 33 | x /= 10; 34 | } 35 | 36 | if (negativeNum) 37 | { 38 | return -1 * ans; 39 | } 40 | 41 | return ans; 42 | } 43 | 44 | int bitwiseComplement(int n) 45 | { 46 | if (n == 0) 47 | return 1; 48 | 49 | int mask = 0; 50 | int m = n; 51 | while (m != 0) 52 | { 53 | mask = (mask << 1) | 1; 54 | m = m >> 1; 55 | } 56 | return (~n & mask); 57 | } 58 | 59 | bool isPowerOfTwo(int n) 60 | { 61 | if (n <= 0) 62 | { 63 | return false; 64 | } 65 | 66 | if (n == 1) 67 | { 68 | return true; 69 | } 70 | 71 | if (n % 2 != 0) 72 | { 73 | return false; 74 | } 75 | 76 | return isPowerOfTwo(n / 2); 77 | } 78 | }; -------------------------------------------------------------------------------- /lecture-007=Leetcode_session/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we did problem solving from LeetCode and successfully solved 3 problems in the most optimised manner. -------------------------------------------------------------------------------- /lecture-008=Switch-case_&_functions/Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-008=Switch-case_&_functions/Function.pdf -------------------------------------------------------------------------------- /lecture-008=Switch-case_&_functions/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int factorial(int n) 5 | { 6 | if (n == 0 || n == 1) 7 | return 1; 8 | 9 | return n * factorial(n - 1); 10 | } 11 | 12 | int nCr(int n, int r) 13 | { 14 | return factorial(n) / (factorial(r) * factorial(n - r)); 15 | } 16 | 17 | int countBits(int n) 18 | { 19 | int count = 0; 20 | while (n > 0) 21 | { 22 | if (n & 1) 23 | count++; 24 | 25 | n >> 1; 26 | } 27 | return count; 28 | } 29 | 30 | int fibonacci(int n) 31 | { 32 | if (n == 0) 33 | return 0; 34 | if (n == 1) 35 | return 1; 36 | 37 | int a = 0; 38 | int b = 1; 39 | int count = 2; 40 | int ans; 41 | while (count != n) 42 | { 43 | int c = a + b; 44 | a = b; 45 | b = c; 46 | count++; 47 | ans = c; 48 | } 49 | return ans; 50 | } 51 | 52 | int main(int argc, char const *argv[]) 53 | { 54 | // int n, r; 55 | // cin >> n >> r; 56 | // cout << nCr(n, r) << "\n"; 57 | // int m; 58 | // cin >> m; 59 | // cout << fibonacci(m) << endl; 60 | int a, b; 61 | cin >> a >> b; 62 | char op; 63 | int result = 0; 64 | while (true) 65 | { 66 | cin >> op; 67 | cout << "Press q to quit" << endl; 68 | switch (op) 69 | { 70 | case '+': 71 | result += a + b; 72 | break; 73 | 74 | case '-': 75 | result += a - b; 76 | break; 77 | 78 | case '*': 79 | result += a * b; 80 | break; 81 | 82 | case '/': 83 | result += a / b; 84 | break; 85 | 86 | case '%': 87 | result += a % b; 88 | break; 89 | 90 | case 'q': 91 | cout << result << endl; 92 | exit(0); 93 | 94 | default: 95 | cout << "ERROR: Invalid operator. Please try again" << endl; 96 | } 97 | } 98 | return 0; 99 | } -------------------------------------------------------------------------------- /lecture-008=Switch-case_&_functions/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we will study about switch-case statements and functions. 2 | 3 | Let us take a look at switch-case statements first. 4 | The use of switch-case statements comes only in case of multiple cases present to a certain statement and instead of putting too many conditional statements we can simply use switch-case instead.(to avoid violate DRY principle) 5 | 6 | The thing with switch-case statements is that only int and char are allowed to be used in it. 7 | 8 | And also in case of switch-case, only break keyword is valid and not continue keyword. 9 | In fact in many programming languages, including C, C++, Java, and others, the continue keyword is not used within switch-case statements because it's not designed to work in that context. 10 | 11 | The continue statement is typically used in loop constructs like for, while, or do-while to skip the rest of the code within the loop's body for the current iteration and move to the next iteration. It's not meant to be used to control the flow within switch-case constructs, which are primarily used for multi-way branching. 12 | 13 | In a switch-case statement, once a case is matched, the code execution starts from that case and continues until the end of the switch block or until a break statement is encountered. The break statement is used to exit the switch block after executing the code associated with the matched case. Using continue wouldn't make sense in this context because there's no concept of "skipping" to the next iteration like in a loop. 14 | 15 | However, some languages provide mechanisms to fall through from one case to another without a break statement (e.g., in C, if no break statement is encountered, control falls through to the next case). In such cases, using continue would disrupt this fall-through behavior and cause unintended consequences. 16 | 17 | Therefore, to control the flow within a switch-case statement, programmers use break to exit the switch block or allow the fall-through behavior where necessary. 18 | 19 | We also leaned more about exit(). 20 | In C++, the exit() function is part of the header and is used to terminate a program. It allows you to exit a program and return a status code to the operating system. The exit() function takes an integer argument, which represents the exit status of the program. 21 | 22 | Here's a simple example: 23 | 24 | #include 25 | int main() { 26 | // Your program logic here 27 | // Exit the program with a status code of 0 28 | exit(0); 29 | } 30 | 31 | The integer argument passed to exit() is often used to indicate the success or failure of the program. By convention, a return value of 0 typically indicates successful execution, while non-zero values indicate errors or abnormal termination. 32 | Here's an example where the program exits with a non-zero status: 33 | 34 | #include 35 | #include 36 | int main() { 37 | // Your program logic here 38 | // Exit the program with a status code of 1 39 | exit(1); 40 | } 41 | 42 | It's important to note that calling exit() will immediately terminate the program, and no further code in the program will be executed after the call to exit(). This includes any destructors for automatic objects (variables with automatic storage duration). 43 | 44 | If you need to perform cleanup operations before exiting, it's often better to use the atexit() function or rely on C++'s destructors and resource management techniques. 45 | 46 | Here's an example using atexit(): 47 | 48 | #include 49 | #include 50 | void cleanupFunction() { 51 | std::cout << "Performing cleanup before exit." << std::endl; 52 | // Additional cleanup logic 53 | } 54 | int main() { 55 | // Your program logic here 56 | // Register the cleanup function 57 | atexit(cleanupFunction); 58 | // Exit the program with a status code of 0 59 | exit(0); 60 | } 61 | 62 | This way, cleanupFunction() will be called before the program exits, allowing you to perform necessary cleanup operations. 63 | 64 | 65 | Pass by value and pass by reference are two fundamental ways in which programming languages handle passing arguments to functions or methods. These concepts are particularly relevant in languages like C, C++, Java, and others. 66 | 67 | Pass by Value: 68 | In pass by value, a copy of the actual parameter's value is passed to the function or method being called. This means that any modifications made to the parameter inside the function do not affect the original variable in the caller's scope. 69 | 70 | Characteristics: 71 | Value Copying: The function receives a copy of the parameter's value, not the parameter itself. 72 | 73 | Isolation: Changes made to the parameter inside the function are confined to the function's scope and do not reflect in the caller's scope. 74 | 75 | Immutable: The original value passed remains unchanged. 76 | 77 | Example (C++): 78 | cpp 79 | Copy code 80 | #include 81 | 82 | void increment(int x) { 83 | x++; // Changes are local to this function 84 | } 85 | 86 | int main() { 87 | int num = 5; 88 | increment(num); 89 | std::cout << num; // Output: 5 (unchanged) 90 | return 0; 91 | } 92 | Pass by Reference: 93 | In pass by reference, instead of passing a copy of the value, the function receives a reference or address of the actual parameter. Any changes made to the parameter inside the function directly affect the original variable in the caller's scope. 94 | 95 | Characteristics: 96 | Direct Access: The function operates directly on the original parameter. 97 | 98 | Mutability: Changes made to the parameter inside the function reflect in the caller's scope. 99 | 100 | Efficiency: Avoids creating unnecessary copies of large data structures. 101 | 102 | Example (C++): 103 | cpp 104 | Copy code 105 | #include 106 | 107 | void increment(int& x) { 108 | x++; // Changes are reflected in the original variable 109 | } 110 | 111 | int main() { 112 | int num = 5; 113 | increment(num); 114 | std::cout << num; // Output: 6 (modified) 115 | return 0; 116 | } 117 | Related Concepts: 118 | Pointers: In languages like C and C++, pass by reference is often implemented using pointers, which store the memory address of a variable. 119 | 120 | Memory Management: Pass by reference requires careful consideration of memory management to avoid issues like dangling references or memory leaks. 121 | 122 | Const Reference: Some languages support passing parameters by const reference, allowing read-only access to the original variable within the function. 123 | 124 | Pass by Value-Result: This is a hybrid approach where the function receives a copy of the value, but changes made to the parameter inside the function are reflected back to the original variable upon function completion. 125 | 126 | Immutable Data Structures: In some languages, like functional programming languages, data structures are immutable by default, meaning they cannot be modified after creation. This simplifies pass by value semantics as no unexpected modifications can occur. 127 | 128 | Understanding these concepts is crucial for designing efficient and predictable programs, especially when dealing with complex data structures or when performance is a concern. -------------------------------------------------------------------------------- /lecture-009=Introduction_to_arrays/Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-009=Introduction_to_arrays/Arrays.pdf -------------------------------------------------------------------------------- /lecture-009=Introduction_to_arrays/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void reverseAnArray(int arr[], int size) 5 | { 6 | int start = 0; 7 | int end = size - 1; 8 | while (start < end) 9 | swap(arr[start++], arr[end--]); 10 | } 11 | 12 | int main(int argc, char const *argv[]) 13 | { 14 | int evenArr[10] = {1, 3, 5, 6, 32, 4, 45, 56, 54, 423}; 15 | int oddArr[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; 16 | reverseAnArray(evenArr, 10); 17 | reverseAnArray(oddArr, 11); 18 | for (int i = 0; i < 10; i++) 19 | cout << evenArr[i] << " " << oddArr[i] << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /lecture-010=Leetcode_session/Array Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-010=Leetcode_session/Array Questions.pdf -------------------------------------------------------------------------------- /lecture-010=Leetcode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | // int findUnique(int *arr, int size) 9 | // { 10 | // int unique = 0; 11 | // for (int i = 0; i < size; i++) 12 | // unique ^= arr[i]; 13 | // return unique; 14 | // } 15 | 16 | void swapAlternate(int arr[], int size) 17 | { 18 | for (int i = 1; i < size; i += 2) 19 | swap(arr[i], arr[i - 1]); 20 | } 21 | 22 | void printArray(int *arr[]) 23 | { 24 | int size = sizeof(arr) / sizeof(int); 25 | cout << "The array is: "; 26 | for (int i = 0; i < size; i++) 27 | cout << (*arr)[i] << " "; 28 | } 29 | 30 | int findDuplicate(vector &arr) 31 | { 32 | int slow = arr[0]; 33 | int fast = arr[0]; 34 | 35 | do 36 | { 37 | slow = arr[slow]; 38 | fast = arr[arr[fast]]; 39 | } while (slow != fast); 40 | 41 | fast = arr[0]; 42 | while (slow != fast) 43 | { 44 | slow = arr[slow]; 45 | fast = arr[fast]; 46 | } 47 | 48 | return slow; 49 | } 50 | 51 | // Approach of above mentioned code mentioned below:- 52 | // Your provided code is already quite efficient(the code i provided chatgpt where i solved this problem using unordered_maps), with a time complexity of O(n) where n is the size of the input array arr. However, we can optimize it slightly by eliminating the need for the unordered_map and using a different approach to find the duplicate. 53 | // Here's an optimized version using Floyd's Tortoise and Hare algorithm (also known as cycle detection algorithm) which has the same time complexity but uses constant space, thus making it more memory-efficient. 54 | // This algorithm works by considering the array elements as nodes in a linked list. Since each number between 1 and N-1 is present at least once, and there is one duplicate, there's at least one cycle in this linked list. The algorithm then uses two pointers, one moving one step at a time (slow) and the other moving two steps at a time (fast). When they meet, it indicates that there's a cycle. After that, we reset one pointer to the start and move both pointers at the same speed; they will meet at the beginning of the cycle, which is the duplicate number. 55 | // The time complexity of both the original and the optimized versions is O(n), where n is the size of the input array. However, the optimized version uses constant space, while the original version uses extra space to store the count of each element, resulting in a space complexity of O(n). Therefore, the optimized version is more memory-efficient. 56 | 57 | vector findDuplicates(vector &nums) 58 | { 59 | int n = nums.size(); 60 | for (int i = 0; i < n; i++) 61 | { 62 | if (nums[i] < 0) 63 | continue; 64 | 65 | else 66 | { 67 | int e = nums[i] - 1; 68 | if (nums[e] > 0) 69 | { 70 | swap(nums[e], nums[i--]); 71 | nums[e] = -1; 72 | } 73 | else 74 | { 75 | nums[e]--; 76 | nums[i] = 0; 77 | } 78 | } 79 | } 80 | 81 | int j = 0; 82 | for (int i = 0; i < n; i++) 83 | if (nums[i] == -2) 84 | nums[j++] = (i + 1); 85 | nums.resize(j); 86 | return nums; 87 | } 88 | 89 | int findDuplicate(vector &arr) 90 | { 91 | // unordered_map count; 92 | // for(int i: arr) 93 | // count[i]++; 94 | 95 | // for(auto pair: count) 96 | // { 97 | // if(pair.second==2) 98 | // return pair.first; 99 | // } 100 | 101 | // return -1; 102 | int ans = 0; 103 | int n = arr.size(); 104 | for (int i = 0; i < n; i++) 105 | { 106 | if (i == n - 1) 107 | { 108 | ans ^= arr[i]; 109 | continue; 110 | } 111 | 112 | ans ^= (i + 1); 113 | ans ^= arr[i]; 114 | } 115 | return ans; 116 | } 117 | 118 | bool uniqueOccurrences(vector &arr) 119 | { 120 | std::unordered_map countMap; 121 | for (int num : arr) 122 | { 123 | countMap[num]++; 124 | } 125 | 126 | std::unordered_set uniqueCounts; 127 | for (const auto &entry : countMap) 128 | { 129 | if (!uniqueCounts.insert(entry.second).second) 130 | return false; 131 | } 132 | return true; 133 | } 134 | 135 | void sort012(int *arr, int n) 136 | { 137 | int j = 0; 138 | int i = n - 1; 139 | int start = 0; 140 | while (start <= i) 141 | { 142 | if (arr[start] == 2) 143 | { 144 | swap(arr[i], arr[start]); // Dutch national flag algorithm 145 | i--; 146 | } 147 | else if (arr[start] == 0) 148 | { 149 | swap(arr[j], arr[start]); 150 | j++; 151 | start++; 152 | } 153 | else 154 | { 155 | start++; 156 | } 157 | } 158 | } 159 | 160 | vector findArrayIntersection(vector &arr1, int n, vector &arr2, int m) 161 | { 162 | vector ans; 163 | int i = 0; 164 | int j = 0; 165 | while(iarr2[j]) 175 | j++; 176 | 177 | else if(arr1[i]> pairSum(vector &arr, int s){ 184 | vector> ans; 185 | for(int i = 0; i> findTriplets(vector arr, int n, int K) { 197 | vector> result; 198 | sort(arr.begin(), arr.end()); 199 | 200 | for (int i = 0; i < n - 2; ++i) { 201 | if (i == 0 || (i > 0 && arr[i] != arr[i - 1])) { 202 | int left = i + 1, right = n - 1, target = K - arr[i]; 203 | while (left < right) { 204 | int sum = arr[left] + arr[right]; 205 | if (sum == target) { 206 | result.push_back({arr[i], arr[left], arr[right]}); 207 | while (left < right && arr[left] == arr[left + 1]) left++; 208 | while (left < right && arr[right] == arr[right - 1]) right--; 209 | left++; 210 | right--; 211 | } else if (sum < target) { 212 | left++; 213 | } else { 214 | right--; 215 | } 216 | } 217 | } 218 | } 219 | 220 | return result; 221 | } 222 | 223 | int sort0and1() // solve using counting sort, sort stl, two pointer approach, dutch national flag algorithm 224 | { 225 | 226 | } 227 | 228 | // find the subarray of any size that sums upto required target sum 229 | 230 | int main(int argc, char const *argv[]) 231 | { 232 | 233 | return 0; 234 | } -------------------------------------------------------------------------------- /lecture-010=Leetcode_session/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we have solved many LeetCode and Codestudio questions about the topic of arrays and have found and compiled their most optimized solutions after lots of research. 2 | 3 | find ways to swap entities 4 | whenever we talk about unique, we talk about either set or xor, info about them 5 | more info about *arr 6 | solve all questions with the approach discussed in video -------------------------------------------------------------------------------- /lecture-011=Time_&_space_complexity/Complexity1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-011=Time_&_space_complexity/Complexity1.pdf -------------------------------------------------------------------------------- /lecture-012=Binary_search/Binary Search I.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-012=Binary_search/Binary Search I.pdf -------------------------------------------------------------------------------- /lecture-012=Binary_search/code.cpp: -------------------------------------------------------------------------------- 1 | // 4 types of binary search code(increasing and decreasing sort)(using for loop, using while loop) -------------------------------------------------------------------------------- /lecture-012=Binary_search/notes.txt: -------------------------------------------------------------------------------- 1 | binary search info 2 | complexity calculation 3 | binary search famous application problems and where to apply it -------------------------------------------------------------------------------- /lecture-013=Leetcode_session/Binary Search I.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-013=Leetcode_session/Binary Search I.pdf -------------------------------------------------------------------------------- /lecture-013=Leetcode_session/code.cpp: -------------------------------------------------------------------------------- 1 | // class Solution { 2 | // public: 3 | // int pivotIndex(vector& nums) { 4 | // ios_base::sync_with_stdio(false); 5 | // cin.tie(nullptr); 6 | // int totalSum = 0; 7 | // int n = nums.size(); 8 | // for (int num : nums) { 9 | // totalSum += num; 10 | // } 11 | // int leftSum = 0; 12 | // for (int i = 0; i < n; i++) { 13 | // if (leftSum == totalSum - leftSum - nums[i]) { 14 | // return i; 15 | // } 16 | // leftSum += nums[i]; 17 | // } 18 | // return -1; 19 | // } 20 | // }; 21 | 22 | 23 | // class Solution { 24 | // public: 25 | // int peakIndexInMountainArray(vector& arr) { 26 | // ios_base::sync_with_stdio(false); 27 | // cin.tie(nullptr); 28 | // int left = 0; 29 | // int right = arr.size() - 1; 30 | // int mid; 31 | // while (left < right) { 32 | // mid = left + (right - left) / 2; 33 | // if (arr[mid] > arr[mid + 1]) { 34 | // right = mid; 35 | // } else { 36 | // left = mid + 1; 37 | // } 38 | // } 39 | // return left; 40 | // } 41 | // }; 42 | 43 | 44 | // int secondOccurence(vector& arr, int n, int k) 45 | // { 46 | // int start = 0; 47 | // int end = n-1; 48 | // int ans = -1; 49 | // while(start<=end) 50 | // { 51 | // int mid = start + (end-start)/2; 52 | // if(arr[mid]k) 56 | // end = mid-1; 57 | 58 | // if(arr[mid]==k) 59 | // { 60 | // ans = mid; 61 | // start++; 62 | // } 63 | // } 64 | // return ans; 65 | // } 66 | 67 | // int firstOccurence(vector& arr, int n, int k) 68 | // { 69 | // int start = 0; 70 | // int end = n-1; 71 | // int ans = -1; 72 | // while(start<=end) 73 | // { 74 | // int mid = start + (end-start)/2; 75 | // if(arr[mid]k) 79 | // end = mid-1; 80 | 81 | // if(arr[mid]==k) 82 | // { 83 | // ans = mid; 84 | // end--; 85 | // } 86 | // } 87 | // return ans; 88 | // } 89 | 90 | // pair firstAndLastPosition(vector& arr, int n, int k) 91 | // { 92 | // pair ans; 93 | // ans.first = firstOccurence(arr, n, k); 94 | // ans.second = secondOccurence(arr, n, k); 95 | // return ans; 96 | // } -------------------------------------------------------------------------------- /lecture-013=Leetcode_session/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture, we solved 3 problems from leetcode and codestudio and learned about how they can be solved in optimized manner. 2 | 3 | We also learned that- 4 | The space complexity of my code, despite using the same amount of space as the optimized solution provided, might be displayed as higher on LeetCode due to how the platform evaluates space complexity. Here are a few possible reasons: 5 | 6 | Auxiliary space consideration: LeetCode may consider not only the space used explicitly by your code but also any additional auxiliary space used, such as stack space for function calls or any other hidden space usage. 7 | 8 | Compiler optimizations: LeetCode may compile and run your code in a different environment or with different compiler flags than what you might use locally. Compiler optimizations can affect how much memory your code consumes. 9 | 10 | Memory allocation specifics: The way memory is allocated and managed in the online judge environment of LeetCode might differ from your local environment, leading to variations in reported memory usage. 11 | 12 | Additional overhead: There might be additional overhead or bookkeeping required by the online judge platform for running and evaluating your code, which could contribute to differences in reported space complexity. 13 | 14 | In summary, while my code may use the same amount of space as the optimized solution provided, the reported space complexity on LeetCode might differ due to various factors related to the platform's evaluation process and environment. 15 | 16 | 17 | We also learned that in C++, std::pair is a templated class provided by the Standard Template Library (STL) that allows you to encapsulate two heterogeneous objects into a single entity. It's a very handy utility when you need to associate two values together but don't necessarily want to define a separate struct or class for that purpose. 18 | 19 | Here's a comprehensive breakdown of std::pair: 20 | 21 | 1. Template Class: 22 | std::pair is a template class, meaning it can hold elements of any data type. It's defined in the header. 23 | 24 | 2. Pair Structure: 25 | Each std::pair contains two elements, typically referred to as first and second. These elements can be of different types. 26 | 27 | 3. Creating Pairs: 28 | You can create std::pair instances in several ways: 29 | 30 | Explicitly providing the types: 31 | 32 | cpp 33 | Copy code 34 | std::pair myPair(5, 3.14); 35 | Using make_pair function (since C++11): 36 | 37 | auto myPair = std::make_pair(5, 3.14); 38 | 4. Accessing Elements: 39 | You can access the elements of the pair using the first and second member variables: 40 | 41 | std::cout << "First: " << myPair.first << ", Second: " << myPair.second << std::endl; 42 | 5. Utility Functions: 43 | The header provides utility functions to work with pairs: 44 | 45 | make_pair: Constructs a pair from two values. 46 | swap: Swaps the contents of two pairs. 47 | get: Allows access to elements of the pair by index (since C++17). 48 | 6. Using with Standard Containers: 49 | Pairs are commonly used in conjunction with standard containers like std::map, std::unordered_map, std::set, std::multimap, and std::multiset to associate keys with values. 50 | 51 | 7. Example Usage: 52 | Here's an example demonstrating the usage of std::pair: 53 | 54 | #include 55 | #include 56 | 57 | int main() { 58 | std::pair student(1, "John"); 59 | std::cout << "ID: " << student.first << ", Name: " << student.second << std::endl; 60 | return 0; 61 | } 62 | 8. When to Use: 63 | std::pair is handy for one-off associations or returning multiple values from a function without needing to define a separate struct or class. 64 | 65 | 9. Limitations: 66 | std::pair is useful for simple use cases, but for more complex associations or structures, defining a custom struct or class might be more appropriate. 67 | 68 | 10. C++17 and Beyond: 69 | With C++17, std::pair gained some additional functionality, like the get function for accessing elements by index. 70 | 71 | That's a comprehensive overview of std::pair in C++. It's a simple yet powerful tool for bundling two values together. 72 | 73 | 74 | 8:16 mention correction mentioned in video in code 75 | 25:20 Do total number of occurence code using binary search 76 | Solve problems in code section with the provided code only 77 | -------------------------------------------------------------------------------- /lecture-014=LeetCode_session/Binary Search Ques2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-014=LeetCode_session/Binary Search Ques2.pdf -------------------------------------------------------------------------------- /lecture-014=LeetCode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int pivotElement(vector &arr) 6 | { 7 | int start = 0; 8 | int end = arr.size() - 1; 9 | while (start < end) 10 | { 11 | // int mid = start + (end - start) / 2; 12 | 13 | // if (arr[mid] <= arr[start] && arr[mid] <= arr[end]) // changing this we can write code of pivot element being largest one 14 | // return arr[mid]; 15 | 16 | // else if (arr[mid] > arr[start]) 17 | // start = mid + 1; 18 | 19 | // else if (arr[mid] < arr[end]) 20 | // end = mid - 1; 21 | 22 | int mid = start + (end - start) / 2; 23 | if(arr[mid]>=arr[0]) 24 | start = mid+1; 25 | 26 | else 27 | end = mid; 28 | } 29 | return start; 30 | } 31 | 32 | int searchRotatedArray(vector &arr, int key) 33 | { 34 | int start = 0; 35 | int end = arr.size() - 1; 36 | while (start <= end) 37 | { 38 | int mid = start + (end - start) / 2; 39 | if (arr[mid] == key) 40 | return mid; 41 | 42 | if (arr[start] <= arr[mid]) 43 | { 44 | // If the key lies within the range of the left half 45 | if (key >= arr[start] && key < arr[mid]) 46 | end = mid - 1; 47 | else 48 | start = mid + 1; 49 | } 50 | 51 | else 52 | { 53 | // If the key lies within the range of the right half 54 | if (key > arr[mid] && key <= arr[end]) 55 | start = mid + 1; 56 | else 57 | end = mid - 1; 58 | } 59 | } 60 | return -1; 61 | } 62 | 63 | int findPivot(vector &arr, int n) { 64 | int start = 0; 65 | int end = n - 1; 66 | while (start < end) { 67 | int mid = start + (end - start) / 2; 68 | if (arr[mid] > arr[end]) 69 | start = mid + 1; 70 | else 71 | end = mid; 72 | } 73 | return start; 74 | } 75 | 76 | int binarySearch(vector& arr, int start, int end, int k) { 77 | while (start <= end) { 78 | int mid = start + (end - start) / 2; 79 | if (arr[mid] == k) 80 | return mid; 81 | else if (arr[mid] < k) 82 | start = mid + 1; 83 | else 84 | end = mid - 1; 85 | } 86 | return -1; 87 | } 88 | 89 | int search(vector& arr, int n, int k) { 90 | int pivot = findPivot(arr, n); 91 | if (k >= arr[pivot] && k <= arr[n - 1]) 92 | return binarySearch(arr, pivot, n - 1, k); 93 | else 94 | return binarySearch(arr, 0, pivot - 1, k); 95 | } 96 | 97 | int floorSqrt(int n) 98 | { 99 | long long int start = 0; 100 | long long int end = n; 101 | while(start <= end) 102 | { 103 | long long int mid = start + (end-start)/2; 104 | 105 | if(mid*mid == n) 106 | return mid; 107 | 108 | if(mid*mid > n) 109 | end = mid-1; 110 | 111 | else 112 | start = mid+1; 113 | } 114 | return start-1; 115 | } 116 | 117 | int main(int argc, char const *argv[]) 118 | { 119 | // vector elements = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5}; 120 | vector elements = {3, 7, 8, 17, 19, 21, 0, 1, 2}; 121 | // int temp; 122 | // while(cin>>temp) 123 | // elements.push_back(temp); 124 | 125 | int pivot = pivotElement(elements); 126 | cout << pivot << "\n"; 127 | 128 | // while (true) 129 | // { 130 | // char sample; 131 | // cout << "write q to exit" << endl; 132 | // cin >> sample; 133 | // if (sample == 'q') 134 | // break; 135 | 136 | // int key; 137 | // cin >> key; 138 | 139 | // int index = searchRotatedArray(elements, key); 140 | // cout << index << endl; 141 | // } 142 | return 0; 143 | } -------------------------------------------------------------------------------- /lecture-015=Leetcode_session/Binary Search Question3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-015=Leetcode_session/Binary Search Question3.pdf -------------------------------------------------------------------------------- /lecture-015=Leetcode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | bool totalSum(int mid, vector &trees) 8 | { 9 | int total = 0; 10 | for (int i = 0; i < trees.size(); i++) 11 | { 12 | if (mid > trees[i]) 13 | continue; 14 | 15 | total += trees[i] - mid; 16 | } 17 | return total; 18 | } 19 | 20 | int main() 21 | { 22 | int n, m; 23 | cin >> n >> m; 24 | vector trees(n); 25 | for (int i = 0; i < n; i++) 26 | cin >> trees[i]; 27 | 28 | int start = 0; 29 | int end = 0; 30 | accumulate(trees.begin(), trees.end(), end); 31 | while (start < end) 32 | { 33 | int mid = start + (end - start) / 2; 34 | int total = totalSum(mid, trees); 35 | if (total == m) 36 | break; 37 | 38 | if (total > m) 39 | start = mid + 1; 40 | 41 | else 42 | end = mid - 1; 43 | } 44 | cout << start << endl; 45 | return 0; 46 | } 47 | 48 | // bool ispossible(vector rank, int m, int mid) 49 | // { 50 | // int totalorder = 0; 51 | // for (int i = 0; i < rank.size(); i++) 52 | // { 53 | // int numoforder = 1; 54 | // int mins = rank[i] * numoforder; 55 | // while (mins <= mid) 56 | // { 57 | // totalorder++; 58 | // numoforder++; 59 | // mins += rank[i] * numoforder; 60 | // } 61 | // } 62 | // if (totalorder >= m) 63 | // return true; 64 | // else 65 | // return false; 66 | // } 67 | 68 | // int minCookTime(vector &rank, int m) 69 | // { 70 | // sort(rank.begin(), rank.end()); 71 | // int sum = 0; 72 | // int maxi = rank[rank.size() - 1]; 73 | // for (int i = 1; i <= m; i++) 74 | // { 75 | // sum += i * maxi; 76 | // } 77 | // int s = 0, e = sum; 78 | // int mid = s + (e - s) / 2; 79 | // int ans = -1; 80 | // while (s <= e) 81 | // { 82 | // if (ispossible(rank, m, mid)) 83 | // { 84 | // ans = mid; 85 | // e = mid - 1; 86 | // } 87 | // else 88 | // { 89 | // s = mid + 1; 90 | // } 91 | // mid = s + (e - s) / 2; 92 | // } 93 | // return ans; 94 | // } 95 | 96 | // bool distance(vector &stalls, int mid, int k) 97 | // { 98 | // int cowcount = 1; 99 | // int position = stalls[0]; 100 | // for (int i = 0; i < stalls.size(); i++) 101 | // { 102 | // if (stalls[i] - position >= mid) 103 | // { 104 | // cowcount++; 105 | // position = stalls[i]; 106 | // if (cowcount >= k) 107 | // return true; 108 | // } 109 | // } 110 | // return false; 111 | // } 112 | 113 | // int aggressiveCows(vector &stalls, int k) 114 | // { 115 | // sort(stalls.begin(), stalls.end()); 116 | // int s = 0; 117 | // int ans = -1; 118 | // int max = *max_element(stalls.begin(), stalls.end()); 119 | // int min = *min_element(stalls.begin(), stalls.end()); 120 | // int e = max - min; 121 | // while (s <= e) 122 | // { 123 | // int mid = s + (e - s) / 2; 124 | // if (distance(stalls, mid, k) == true) 125 | // { 126 | // ans = mid; 127 | // s = mid + 1; 128 | // } 129 | // else 130 | // e = mid - 1; 131 | // } 132 | // return ans; 133 | // } 134 | 135 | // bool isPossible(vector time, int n, int m, long long mid) 136 | // { 137 | // long long timecount = 0; 138 | // long long days = 1; 139 | // for (long long i = 0; i < m; i++) 140 | // { 141 | // if (timecount + time[i] <= mid) 142 | // timecount += time[i]; 143 | // else 144 | // { 145 | // days++; 146 | // if (days > n || time[i] > mid) 147 | // return false; 148 | // timecount = time[i]; 149 | // } 150 | // } 151 | // return true; 152 | // } 153 | 154 | // long long ayushGivesNinjatest(int n, int m, vector time) 155 | // { 156 | // long long sum = 0; 157 | // long long ans = -1; 158 | // for (long long i = 0; i < m; i++) 159 | // { 160 | // sum += time[i]; 161 | // } 162 | // long long start = 0; 163 | // long long end = sum; 164 | // while (start <= end) 165 | // { 166 | // long long mid = start + (end - start) / 2; 167 | // if (isPossible(time, n, m, mid)) 168 | // { 169 | // ans = mid; 170 | // end = mid - 1; 171 | // } 172 | // else 173 | // start = mid + 1; 174 | // } 175 | // return ans; 176 | // } 177 | 178 | // bool isPossible(vector &boards, int k, int mid) 179 | // { 180 | // int pcount = 1; 181 | // int boardsum = 0; 182 | // int n = boards.size(); 183 | // for (int i = 0; i < n; i++) 184 | // { 185 | // if (boardsum + boards[i] <= mid) 186 | // { 187 | // boardsum += boards[i]; 188 | // } 189 | // else 190 | // { 191 | // pcount++; 192 | // if (pcount > k || boards[i] > mid) 193 | // { 194 | // return false; 195 | // } 196 | // boardsum = boards[i]; 197 | // } 198 | // } 199 | // return true; 200 | // } 201 | 202 | // int findLargestMinDistance(vector &boards, int k) 203 | // { 204 | // int start = 0; 205 | // int sum = 0; 206 | // int n = boards.size(); 207 | // for (int i = 0; i < n; i++) 208 | // { 209 | // sum += boards[i]; 210 | // } 211 | // int end = sum; 212 | // int mid = start + (end - start) / 2; 213 | // int ans = -1; 214 | 215 | // while (start <= end) 216 | // { 217 | // if (isPossible(boards, k, mid)) 218 | // { 219 | // ans = mid; 220 | // end = mid - 1; 221 | // } 222 | // else 223 | // { 224 | // start = mid + 1; 225 | // } 226 | // mid = start + (end - start) / 2; 227 | // } 228 | // return ans; 229 | // } -------------------------------------------------------------------------------- /lecture-015=Leetcode_session/notes.txt: -------------------------------------------------------------------------------- 1 | How do we know that we are going to use binary search?? 2 | 3 | Whenever terms like maximum solution, minimum solution, floor, valley, ceiling, sorted array etc are used and the constraints are high then we can think of using binary search. Also in problems where we can see that if the answer is not one specific number and I can neglect all numbers smaller and bigger than that, cutting off a possible pathway from the search space given for finding the solution, then also we can think of applying binary search to the problem. 4 | 5 | Aggresive cows problem approach explanation- 6 | 1. LINEAR SEARCH: MUST READ TO UNDERSTAND CONCEPT 7 | 8 | So we are given position of stalls and cows to place in those stalls. 9 | 10 | Condition 1: 11 | If there are more cows than the position of stalls, there is no place to keep all the cows. 12 | 13 | Condition 2: 14 | a. As we have to find the difference between stalls, best way is to sort them so that we can code easily. It helps to iterate without confusion. 15 | 16 | b. Now, lets think, I have a sorted array. If i place first cow at first position of sorted stalls(array), where can I keep the second cow? Obviously after that, after 1 distance. Similarly, another cow after that. This solution is possible. So it can be our answer. 17 | 18 | c. But our question says largest distance, so lets check if its possible in 2 distance or not. We again place first cow at first position and increase distance by 2 this time. First cow, add 2 positions then second cow and so on. If all cow fit, that is better solution than distance 1. 19 | 20 | d. Again we try for distance is 3 and check if all cow fit. In this way at point where our total number of cow cannot fit, the previous distance is our answer (means, if my all cows don't fit in given number of limited stalls while i keep them at distance of 3, my largest possible distance I can place them is 2). 21 | 22 | Another important point mentioned in all the questions was that the sub-arrays that we have to take have to be contiguous else we would not have been able to implement binary search. 23 | 24 | 25 | 2. BINARY SEARCH 26 | 27 | a. As you understood linear search, you saw that, if cow didn't fit at distance of 3, then it obviously won't fit when I apply the distance of 4, 5, 6, 7,……. . This shows, we can remove half part of the array which comes after 3 just by checking on 3. That's why we apply binary search. 28 | 29 | b. In linear search we were checking distance one by one; firstly 1 then 2 and so on. To avoid that we use binary search. For binary search we need, start which is minimum and end which is maximum possible distance. 30 | 31 | c. Our minimum distance at which I can place all the cows is 0 (means all cow are together in same stall without any distance). Our maximum distance is between, when we keep one cow at first stall and another cow at last stall. So maximum distance is (maximum/last element of sorted array - minimum/first element sorted of array). So we got minimum maximum, we apply binary search and find mid. 32 | 33 | d. Max and min value were distance right ? So , mid value is also distance. 34 | 35 | e. In linear search we were checking for distance 1, then 2 and 3 right, so here we check for distance of mid value. 36 | 37 | f. While mid is the distance between our cows stall, will all cows fit in those limited number of stalls?? If yes, that is our possible answer. We have to find the largest distance right ? So we know if it satisfies for mid, it will satisfy for every value less than mid. That's why we again run binary search from mid+1 to end distance (meaning start position will be mid+1 now). In this way we check by taking out mid and if for that distance we can place cow update answer as that mid distance. 38 | 39 | g. ELSE PART: We check to find largest in mid+1 position. Else If mid distance doesn't fit all cows in those limited number of stalls, we know any distance above that mid distance can't fit cows. So we take end to mid-1 and repeat binary search. So, like this we find the largest minimum distance. 40 | 41 | I didn't explain the code cause if you understand this theory, you can write code yourself. Also don't get confused as bool function is used there. 42 | 43 | We could do in same function also but coders are lazy and don't want to right many lines of code so they just make one function and call it. 44 | 45 | Time complexity= O(logN) (binary search) * O(N) (checking distance is possible or not) so; O(NlogN) 46 | 47 | Space Complexity= Has our code used any extra space, meaning any extra memory?? Not at all. We just play with the numbers by sometimes sorting, or sometimes diving so its O(1) (as no extra space). 48 | 49 | 50 | All the other problems also share the same logic either its book allocation to students or it is painter's partition problem. The only difference being in those we were finding the minimum distance and here we are finding the maximum distance. -------------------------------------------------------------------------------- /lecture-016=Selection_sort/Selection Sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-016=Selection_sort/Selection Sort.pdf -------------------------------------------------------------------------------- /lecture-016=Selection_sort/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | /* 6 | Time Complexity : O(N^2) 7 | Space Complexity : O(1) 8 | 9 | Where 'N' is the length of the given array. 10 | */ 11 | 12 | // This function is used to swap two elements of the array. 13 | void swap(int *first, int *second) 14 | { 15 | int temp = *first; 16 | *first = *second; 17 | *second = temp; 18 | } 19 | 20 | void selectionSort(vector& arr, int n) 21 | { 22 | int minVal; 23 | 24 | // This is used to iterate over all elements of array. 25 | for (int i = 0; i < n - 1; i++) 26 | { 27 | // This is used to store the minimum value index. 28 | minVal = i; 29 | for (int j = i + 1; j < n; j++) 30 | if (arr[j] < arr[minVal]) { 31 | minVal = j; 32 | } 33 | 34 | // Swapping the minimum element with the first element. 35 | swap(&arr[minVal], &arr[i]); 36 | } 37 | } -------------------------------------------------------------------------------- /lecture-016=Selection_sort/notes.txt: -------------------------------------------------------------------------------- 1 | Selection Sort: Overview 2 | 3 | Selection sort is a simple comparison-based sorting algorithm. It works by repeatedly finding the minimum element from the unsorted portion of the array and placing it at the beginning. The algorithm maintains two subarrays: the sorted subarray, which is built up from left to right at the front of the array, and the unsorted subarray at the remaining positions. 4 | 5 | Approach: 6 | 7 | Find the minimum element in the unsorted array. 8 | Swap it with the element at the beginning of the unsorted array. 9 | Move the subarray boundary one element to the right. 10 | Complexity: 11 | 12 | Time Complexity: 13 | Best Case: O(n^2) 14 | Average Case: O(n^2) 15 | Worst Case: O(n^2) 16 | Space Complexity: O(1) - Selection sort is an in-place sorting algorithm. 17 | Applications of Selection Sort: 18 | 19 | Selection sort is suitable for small datasets or when auxiliary memory space is limited. 20 | It can be used in scenarios where the simplicity of implementation is more important than the efficiency of the sorting algorithm. 21 | It's often used as an educational tool to demonstrate the concept of sorting algorithms due to its simplicity. 22 | Approach in Non-Sorting Questions: 23 | Selection sort's approach of finding the minimum (or maximum) can be applied in various non-sorting scenarios such as: 24 | 25 | Finding the smallest or largest element in an array. 26 | Locating the kth smallest or largest element in an array. 27 | Identifying the minimum or maximum value in a collection. 28 | Data Types Sorted: 29 | Selection sort can be applied to sort various data types including: 30 | 31 | Integer numbers 32 | Floating-point numbers 33 | Characters (for sorting strings) 34 | Custom data types (with defined comparison operators) 35 | 36 | Use Case Example: 37 | Consider a scenario where you have a list of students along with their exam scores. You want to rearrange the list in ascending order of scores using selection sort. This can be efficiently done using selection sort, especially if the dataset is not very large. The simplicity of the algorithm makes it suitable for such tasks where a quick, straightforward solution is preferred over more complex sorting algorithms. -------------------------------------------------------------------------------- /lecture-017=Bubble_sort/Bubble Sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-017=Bubble_sort/Bubble Sort.pdf -------------------------------------------------------------------------------- /lecture-017=Bubble_sort/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void bubbleSort(vector &arr, int n) 6 | { 7 | bool swapped = false; 8 | for (int i = 0; i < n; i++) 9 | { 10 | for (int j = 0; j < n - i - 1; j++) 11 | { 12 | if (arr[j] > arr[j + 1]) 13 | { 14 | swapped = true; 15 | swap(arr[j], arr[j + 1]); 16 | } 17 | } 18 | if (swapped == false) // optimization 19 | break; 20 | } 21 | } -------------------------------------------------------------------------------- /lecture-017=Bubble_sort/notes.txt: -------------------------------------------------------------------------------- 1 | Bubble sort: 2 | Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. It is named because smaller elements "bubble" to the top of the list with each iteration. 3 | 4 | Approach: 5 | Start from the beginning of the list. 6 | Compare each pair of adjacent elements. 7 | If they are in the wrong order, swap them. 8 | Repeat this process until no swaps are needed, indicating that the list is sorted. 9 | Complexity: 10 | Time Complexity: 11 | Best Case: O(n) - When the list is already sorted. 12 | Average Case: O(n^2) - When elements are randomly arranged. 13 | Worst Case: O(n^2) - When the list is sorted in reverse order. 14 | Space Complexity: O(1) - Bubble sort only requires a constant amount of additional memory space. 15 | Applications: 16 | Small Data Sets: Bubble sort is suitable for sorting small datasets where efficiency is not a primary concern. 17 | Educational Purposes: It's often used in educational contexts to teach sorting algorithms due to its simplicity. 18 | Debugging: It can be handy for detecting small errors in sorting algorithms. 19 | Use Case: 20 | Bubble sort can be used in scenarios where simplicity and ease of implementation are more important than speed. For instance, in embedded systems with limited resources where the size of data to be sorted is small, or in scenarios where sorting is an occasional task and performance is not a critical factor. 21 | 22 | Data Types: 23 | Bubble sort can be applied to sort various data types including: 24 | 25 | Integers 26 | Floating-point numbers 27 | Characters 28 | Strings 29 | Structured data types (with proper comparison function) 30 | In-place Sort: 31 | Bubble sort is an in-place sorting algorithm, meaning it doesn't require additional storage space to perform sorting. It operates directly on the input array. 32 | 33 | Stability: 34 | Bubble sort is a stable sorting algorithm, meaning that the relative order of equal elements is preserved during sorting. This characteristic makes it suitable for sorting elements where the original order is important. 35 | 36 | 37 | The bubble sort is at its best if the input data is sorted. i.e. If the input data is sorted in the same order as expected output. This can be achieved by using one boolean variable. The boolean variable is used to check whether the values are swapped at least once in the inner loop. Consider the following code snippet: 38 | 39 | int main() 40 | { 41 | int arr[] = {10, 20, 30, 40, 50}, i, j, isSwapped; 42 | int n = sizeof(arr) / sizeof(*arr); 43 | isSwapped = 1; 44 | for(i = 0; i < n - 1 && isSwapped; ++i) 45 | { 46 | isSwapped = 0; 47 | for(j = 0; j < n - i - 1; ++j) 48 | if (arr[j] > arr[j + 1]) 49 | { 50 | swap(&arr[j], &arr[j + 1]); 51 | isSwapped = 1; 52 | } 53 | } 54 | for(i = 0; i < n; ++i) 55 | printf("%d ", arr[i]); 56 | return 0; 57 | } 58 | 59 | In the best-case scenario, the array is already sorted, but just in case, bubble sort performs O(n) comparisons. As a result, the time complexity of bubble sort in the best-case scenario is O(n). 60 | 61 | 1: 8, 7, 9, 22, 5, 13, 31 = 4 swaps 62 | 2: 7, 8, 9, 5, 13, 22, 31 = 3 swaps 63 | 3: 7, 8, 5, 9, 13, 22, 31 = 1 swap 64 | 4: 7, 5, 8, 9, 13, 22, 31 = 1 swap 65 | 5: 5, 7, 8, 9, 13, 22, 31 = 1 swap 66 | 67 | Total 10 swaps are required to sort the array. 68 | 69 | At pass 1: 70 | Number of comparisons = (N-1) 71 | 72 | At pass 2: 73 | Number of comparisons = (N-2) 74 | 75 | At pass 3: 76 | Number of comparisons = (N-3) 77 | 78 | Likewise, 79 | At pass N-1: 80 | Number of comparisons = 1 81 | 82 | Now, calculating total number of comparison required to sort the array 83 | = (N-1) + (N-2) + (N-3) + . . . 2 + 1 84 | = (N-1)*(N-1+1)/2 { by using sum of N natural Number formula } 85 | = (N * (N-1)) / 2 86 | 87 | Total number of comparison (Worst case) = N(N-1)/2 88 | 89 | The worst-case condition for bubble sort occurs when elements of the array are arranged in decreasing order. 90 | In the worst case, the total number of iterations or passes required to sort a given array is (N-1). where ‘N’ is the number of elements present in the array. 91 | 92 | calculating the total number of comparisons required to sort the array 93 | = (N-1) + (N-2) + (N-3) + . . . 2 + 1 94 | = (N-1)*(N-1+1)/2 { by using sum of N natural Number formula } 95 | = (N * (N-1)) / 2 96 | 97 | In the worst case, the Total number of swaps = Total number of comparison 98 | Total number of comparison (Worst case) = N(N-1)/2 99 | Total number of swaps (Worst case) = N(N-1)/2 100 | 101 | So worst case time complexity is O(N^2) as N^2 is the highest order term. 102 | 103 | Bubble Sort is an example of a comparison-based sorting algorithm. A comparison-based sorting algorithm is a type of sorting algorithm that works by comparing pairs of elements in the input data and swapping them if they are in the wrong order. The goal is to rearrange the elements in ascending or descending order. 104 | 105 | Bubble Sort is a comparison-based sorting algorithm because it sorts elements by comparing them pairwise and then making decisions based on those comparisons to rearrange the elements. 106 | 107 | Bubble Sort is an example of a sorting algorithm that Swaps adjacent elements directly 108 | 109 | void bubbleSort(int arr[], int n) 110 | { 111 | int i, j; 112 | bool swapped; 113 | for (i = 0; i < n - 1; i++) { 114 | swapped = false; 115 | for (j = 0; j < n - i - 1; j++) { 116 | 117 | //swap adjacent directly 118 | if (arr[j] > arr[j + 1]) { 119 | swap(&arr[j], &arr[j + 1]); 120 | swapped = true; 121 | } 122 | } 123 | if (swapped == false) 124 | break; 125 | } 126 | } 127 | 128 | Bubble sort performs the swapping of adjacent pairs without the use of any major data structure. Hence Bubble sort algorithm is an in-place algorithm. 129 | 130 | In Bubble Sort, after each pass, the largest element among the unsorted elements "bubbles up" to the last position of the current unsorted portion of the array. This means that with each pass, the largest unsorted element is moved to its correct sorted position at the end of the array. 131 | 132 | Option A: Bubble sort is stable, so this statement is incorrect. 133 | Option B: Bubble sort is a comparison-based algorithm, so this statement is also incorrect. 134 | Option C: Bubble sort has a high time complexity. which is equal to O(n^2). This statement is correct. 135 | Option D: It is adaptable to different data types, it will also work for string and float data types. -------------------------------------------------------------------------------- /lecture-018=Insertion_sort/Insertion Sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-018=Insertion_sort/Insertion Sort.pdf -------------------------------------------------------------------------------- /lecture-018=Insertion_sort/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | /* 5 | Time complexity: O(N^2) 6 | Space complexity: O(1) 7 | 8 | Where 'N' is the size of the array. 9 | */ 10 | 11 | void insertionSort(int n, vector &arr){ 12 | 13 | // To traverse all the elements. 14 | for(int i = 1; i < n; ++i) { 15 | 16 | // To store the current element. 17 | int curr = arr[i]; 18 | 19 | // To traverse previous elements. 20 | int idx = i - 1; 21 | 22 | while(idx >= 0 && arr[idx] > curr) { 23 | 24 | // Change elements position. 25 | arr[idx + 1] = arr[idx]; 26 | 27 | --idx; 28 | } 29 | 30 | // Change current element. 31 | arr[idx + 1] = curr; 32 | } 33 | } -------------------------------------------------------------------------------- /lecture-018=Insertion_sort/notes.txt: -------------------------------------------------------------------------------- 1 | Insertion Sort: 2 | 3 | Insertion Sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is efficient for small datasets or nearly sorted datasets. Insertion Sort works by repeatedly moving elements one at a time into their correct positions. 4 | 5 | Approach: 6 | 7 | Start with the second element (or index 1) and compare it with the elements before it. 8 | If the element is smaller, shift the larger elements one position to the right and insert the current element into its correct position. 9 | Repeat this process for each element in the array. 10 | Complexity: 11 | 12 | Best Case: O(n) comparisons, O(1) swaps (already sorted array). 13 | Average Case: O(n^2) comparisons, O(n^2) swaps. 14 | Worst Case: O(n^2) comparisons, O(n^2) swaps (reverse sorted array). 15 | Data Types: 16 | Insertion Sort can be applied to any data type that supports comparison operators. This includes integers, floating-point numbers, characters, strings, and custom data structures with defined comparison functions. 17 | 18 | Applications: 19 | 20 | Small Datasets: Insertion Sort performs efficiently on small arrays or lists due to its simplicity and low overhead. 21 | Nearly Sorted Data: When the input data is almost sorted, Insertion Sort outperforms other algorithms due to its adaptive nature. 22 | Online Algorithms: Insertion Sort can be used in scenarios where data is continuously arriving, as it can efficiently update the sorted list as new elements are received. 23 | Adaptability: 24 | Insertion Sort is an adaptive sorting algorithm, meaning it performs better on datasets that are already partially sorted. It adapts its behavior based on the input data, making it suitable for a wide range of scenarios. However, it may not perform well on large datasets due to its quadratic time complexity. -------------------------------------------------------------------------------- /lecture-020=Leetcode_session/Lecture 20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-020=Leetcode_session/Lecture 20.pdf -------------------------------------------------------------------------------- /lecture-020=Leetcode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void reverseArray(vector &arr, int m) 6 | { 7 | int start = m + 1; 8 | int end = arr.size() - 1; 9 | while (start < end) 10 | swap(arr[start++], arr[end--]); 11 | } 12 | 13 | void merge(vector &nums1, int m, vector &nums2, int n) 14 | { 15 | vector ans; 16 | int i = 0; 17 | int j = 0; 18 | while (i < m && j < n) 19 | { 20 | if (nums1[i] <= nums2[j]) 21 | ans.push_back(nums1[i++]); 22 | else 23 | ans.push_back(nums2[j++]); 24 | } 25 | 26 | while (i < m) 27 | ans.push_back(nums1[i++]); 28 | 29 | while (j < n) 30 | ans.push_back(nums2[j++]); 31 | 32 | for (int l = 0; l < m + n; l++) 33 | nums1[l] = ans[l]; 34 | } 35 | 36 | void moveZeroes(vector &nums) 37 | { 38 | int nonZeroIndex = 0; // Index to place the next non-zero element 39 | 40 | // Iterate through the array 41 | for (int i = 0; i < nums.size(); i++) 42 | { 43 | // If the current element is non-zero, move it to the next available position 44 | if (nums[i] != 0) 45 | { 46 | if (i != nonZeroIndex) 47 | { // Avoid unnecessary swaps 48 | swap(nums[nonZeroIndex], nums[i]); 49 | } 50 | nonZeroIndex++; // Move the non-zero index forward 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /lecture-020=Leetcode_session/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we solved array problems from leetcode and codestudio and found the optimized approach to solve such problems. 2 | 3 | In reversing an array problem, we can also do that by using stack by pushing and popping elements and storing them in the array to reverse it. 4 | 5 | In merging 2 sorted arrays, we can also do that by adding all elements to an array and using sort function. 6 | 7 | In the move zeroes to the end of the array, we cannot use sort as we have to preserve the order of non zero elements so instead we can use map to map them to their respective index and after single traversal we can add them in respective order to the array and add rest of the elements as zero at the end of array.(counting sort technique). -------------------------------------------------------------------------------- /lecture-021=LeetCode_session/Lecture 21.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-021=LeetCode_session/Lecture 21.pdf -------------------------------------------------------------------------------- /lecture-021=LeetCode_session/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void rotate(vector &nums, int k) 7 | { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | cout.tie(0); 11 | k = k % nums.size(); 12 | reverse(nums.begin(), nums.end() - k); 13 | reverse(nums.end() - k, nums.end()); 14 | reverse(nums.begin(), nums.end()); 15 | } 16 | 17 | // Can also be done by declaring a temp array 18 | 19 | void rotate(vector &nums, int k) 20 | { 21 | int n = nums.size(); 22 | vector temp(n); 23 | 24 | for (int i = 0; i < n; i++) 25 | temp[(i + k) % n] = nums[i]; // less TC more SC approach 26 | 27 | for (int i = 0; i < n; i++) 28 | nums[i] = temp[i]; 29 | } 30 | 31 | vector findArraySum(vector &a, int n, vector &b, int m) 32 | { 33 | int carry = 0; 34 | int i = n - 1; 35 | int j = m - 1; 36 | vector ans; 37 | while (i >= 0 || j >= 0 || carry) 38 | { 39 | int sum = carry; 40 | if (i >= 0) 41 | sum += a[i--]; 42 | if (j >= 0) 43 | sum += b[j--]; 44 | ans.push_back(sum % 10); 45 | carry = sum / 10; 46 | } 47 | reverse(ans.begin(), ans.end()); 48 | return ans; 49 | } 50 | 51 | bool check(vector &nums) 52 | { 53 | int count = 0; 54 | for (int i = 1; i < nums.size(); i++) 55 | { 56 | if (nums[i - 1] > nums[i]) 57 | count++; 58 | } 59 | if (nums[nums.size() - 1] > nums[0]) 60 | count++; 61 | 62 | return count <= 1; 63 | } -------------------------------------------------------------------------------- /lecture-021=LeetCode_session/notes.txt: -------------------------------------------------------------------------------- 1 | In this lecture we solved 3 leetcode questions in most optimized way. Code is available in the code file. -------------------------------------------------------------------------------- /lecture-022=Char_arrays_&_strings/Strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-022=Char_arrays_&_strings/Strings.pdf -------------------------------------------------------------------------------- /lecture-023=Intro_to_2D_arrays/ArrayExercises.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-023=Intro_to_2D_arrays/ArrayExercises.pdf -------------------------------------------------------------------------------- /lecture-025=Pointers_part-1/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(int argc, char const *argv[]) 5 | { 6 | return 0; 7 | } -------------------------------------------------------------------------------- /lecture-026=Pointers_part-2/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-026=Pointers_part-2/code.cpp -------------------------------------------------------------------------------- /lecture-026=Pointers_part-2/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-026=Pointers_part-2/notes.txt -------------------------------------------------------------------------------- /lecture-027=Double_pointers/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-027=Double_pointers/code.cpp -------------------------------------------------------------------------------- /lecture-027=Double_pointers/notes.txt: -------------------------------------------------------------------------------- 1 | pointer info 2 | double pointer info 3 | use case of both 4 | in depth details of memory allocation by computers and address of memory 5 | -------------------------------------------------------------------------------- /lecture-028=Reference_variable/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-028=Reference_variable/code.cpp -------------------------------------------------------------------------------- /lecture-028=Reference_variable/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-028=Reference_variable/notes.txt -------------------------------------------------------------------------------- /lecture-029=Dynamic_memory_2D_array/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-029=Dynamic_memory_2D_array/code.cpp -------------------------------------------------------------------------------- /lecture-029=Dynamic_memory_2D_array/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-029=Dynamic_memory_2D_array/notes.txt -------------------------------------------------------------------------------- /lecture-030=Macros_&_global_variable/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-030=Macros_&_global_variable/code.cpp -------------------------------------------------------------------------------- /lecture-030=Macros_&_global_variable/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-030=Macros_&_global_variable/notes.txt -------------------------------------------------------------------------------- /lecture-031=Recursion_day-1/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-031=Recursion_day-1/code.cpp -------------------------------------------------------------------------------- /lecture-031=Recursion_day-1/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-031=Recursion_day-1/notes.txt -------------------------------------------------------------------------------- /lecture-032=Recursion_day-2/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-032=Recursion_day-2/code.cpp -------------------------------------------------------------------------------- /lecture-032=Recursion_day-2/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-032=Recursion_day-2/notes.txt -------------------------------------------------------------------------------- /lecture-033=Recursion_binary_search/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-033=Recursion_binary_search/code.cpp -------------------------------------------------------------------------------- /lecture-033=Recursion_binary_search/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-033=Recursion_binary_search/notes.txt -------------------------------------------------------------------------------- /lecture-034=Recursion_in_strings/code.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-034=Recursion_in_strings/code.cpp -------------------------------------------------------------------------------- /lecture-034=Recursion_in_strings/notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step-for-interview-prep/Full-DSA-Course_code_and_notes/d81549d0c94bdec17558b9d14c405bdb85329b06/lecture-034=Recursion_in_strings/notes.txt -------------------------------------------------------------------------------- /lecture-035=Merge_sort_using_recursion/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void merge(int *arr, int s, int e) 5 | { 6 | int merge = s + (e-s)/2; 7 | int len1 = mid-s+1; 8 | int len2 = e-mid; 9 | int *first = new int[len1]; 10 | int *second = new int[len2]; 11 | int mainArrayIndex = s; 12 | for(int i = 0; i=e) return; 48 | 49 | int mid = s+ (e-s)/2; 50 | 51 | mergeSort(arr, s, mid); 52 | mergeSort(arr, mid+1, e); 53 | 54 | // merge 55 | merge(arr,s,e); 56 | } 57 | 58 | int main() 59 | { 60 | int arr[8] = {1,5,6,7,12,34,21,3}; 61 | 62 | int n = 8; 63 | 64 | mergeSort(arr, 0, n-1); 65 | 66 | for(int i = 0; i 2 | using namespace std; 3 | 4 | void partition(int *arr, int s, int e) 5 | { 6 | int merge = s + (e-s)/2; 7 | int len1 = mid-s+1; 8 | int len2 = e-mid; 9 | int *first = new int[len1]; 10 | int *second = new int[len2]; 11 | int mainArrayIndex = s; 12 | for(int i = 0; i=e) return; 48 | 49 | // partition karenge 50 | int p = partition(arr, s, e); 51 | 52 | quickSort(arr, s, mid); 53 | quickSort(arr, mid+1, e); 54 | } 55 | 56 | int main() 57 | { 58 | int arr[8] = {1,5,6,7,12,34,21,3}; 59 | 60 | int n = 8; 61 | 62 | quickSort(arr, 0, n-1); 63 | 64 | for(int i = 0; i