├── Arrays └── README.md ├── Basic Math & Number Theory └── README.md ├── Binary Search └── README.md ├── Bits Manipulation └── README.md ├── Data Types & Conditions └── README.md ├── Dynamic Programming ├── Introduction │ ├── Coin Change Problem Discussion.md │ └── README.md ├── README.md └── Subsets, LIS, Counting │ └── README.md ├── Graph Theory ├── Introduction │ └── README.md └── README.md ├── README.md ├── Recursion & Backtracking └── README.md ├── Time Complexity └── README.md └── Two Pointers └── README.md /Arrays/README.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | Arrays are one of the most commonly used data structures in programming and competitive programming. An array is a data structure that stores a collection of elements, each identified by an index. Arrays can be one-dimensional, two-dimensional, or even multi-dimensional. 4 | 5 | Arrays are useful for solving many problems, particularly in competitive programming. Arrays can be used to store and retrieve elements quickly and efficiently, and can be used to create complex data structures such as graphs. Arrays are also often used in algorithms such as sorting, searching, and pattern matching. 6 | 7 | In competitive programming, arrays are used to store information about the problem being solved, such as the input data or the solution. Arrays are also often used to store intermediate results during the execution of an algorithm or to store the solution once it is found. 8 | 9 | 10 | **And we are here to learn them in practice and get benefit of using them.** 11 | **Enjoy Arrays!** 12 | 13 |
14 | 15 | ## My Session @ ICPC SCU 16 | 17 | - [Arrays](https://www.youtube.com/watch?v=gPS2kFoxxf8&t=20s) 18 | 19 | ## Useful Materials 20 | ### Video Materials 21 | * [1D Array Part 1 (Adel Nasim)](https://www.youtube.com/watch?v=eEdRb_7nD08&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=30) 22 | 23 | * [1D Array Part 2 (Adel Nasim)](https://www.youtube.com/watch?v=4394gle-Juk&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=31) 24 | 25 | * [1D Array Part 3 Passing Array to function (Adel Nasim)](https://www.youtube.com/watch?v=t3tOvocy9xw&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=32) 26 | 27 | * [1D Array Part 4 Array of Characters (Adel Nasim)](https://www.youtube.com/watch?v=vIRZCZyx2hA&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=33) 28 | 29 | * [2D Array (Adel Nasim)](https://www.youtube.com/watch?v=TmU8_LvroSI&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=34) 30 | 31 | * [1D Arrays - Intro (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=0HT2-2qD654&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=17) 32 | 33 | * [1D Arrays - Practice (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=38l7MZbUZdM&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=18) 34 | 35 | * [1D Arrays - Homework (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=205MJC3klII&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=19) 36 | 37 | * [Char Arrays - Intro (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=GoqfS1m1BYo&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=20) 38 | 39 | * [Char Arrays - Practice (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=rxKcqvbWkL0&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=21) 40 | 41 | * [Char Arrays - Homework (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=ZKE4VZHS9IY&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=22) 42 | 43 | * [2D Arrays - Intro (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=-GxY9NCG9Bw&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=23) 44 | 45 | * [2D Arrays - Practice (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=rUDC13pfB5E&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=24) 46 | 47 | * [2D Arrays - Homework (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=GUJlDqIMFVA&list=PLPt2dINI2MIbwnEoeHZnUHeUHjTd8x4F3&index=25) 48 | 49 | 50 | ### Reading Materials 51 | * [Arrays in C++ (GeeksforGeeks)](https://www.geeksforgeeks.org/arrays-in-c-cpp/?ref=lbp) 52 | 53 | * [Multidimensional Arrays in C++ (GeeksforGeeks)](https://www.geeksforgeeks.org/multidimensional-arrays-c-cpp/?ref=lbp) 54 | 55 | * [C++ Arrays (W3schools)](https://www.w3schools.com/cpp/cpp_arrays.asp) 56 | 57 | * [C++ Arrays and Loops (W3schools)](https://www.w3schools.com/cpp/cpp_arrays_loop.asp) 58 | 59 | * [C++ Omit Array Size (W3schools)](https://www.w3schools.com/cpp/cpp_arrays_omit.asp) 60 | 61 | * [C++ Get Array Size (W3schools)](https://www.w3schools.com/cpp/cpp_arrays_size.asp) 62 | 63 | * [C++ Multidimentional Arrays (W3schools)](https://www.w3schools.com/cpp/cpp_arrays_multi.asp) 64 | 65 | 66 | ## Practice problems 67 | * [Arrays Sheet (ICPC SCU)](https://codeforces.com/group/n3sTiYtHxI/contest/360152) -------------------------------------------------------------------------------- /Basic Math & Number Theory/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Basic Math and Number Theory 3 | 4 | Math and number theory are important components of competitive programming, as they provide an important foundation for understanding and solving programming problems. Math and number theory can be used to solve problems related to algorithms, data structures, and other areas of computer science. Math and number theory can be used to develop efficient algorithms, analyze data structures, and understand the underlying principles behind problem-solving. They are also relevant to game theory, cryptography, and other areas of computer science. Math and number theory provide the necessary skills and knowledge to solve complex problems, and are essential for success in competitive programming. 5 | 6 | This repository includes materials for learning and understanding basic math and number theory concepts. The topics covered in this repository include, but are not limited to: 7 | 8 | - Introduction to Number Theory 9 | - Divisibility Rules 10 | - Perfect Squares 11 | - Logarithm Basics 12 | - Binary Exponentiation 13 | - Euclidean Algorithm to find the GCD 14 | - Fibonacci Numbers 15 | - Primality Tests 16 | - Sieve of Eratosthenes 17 | - Modular Arithmetic 18 | - LCM 19 | - Factorials 20 | 21 | 22 | **And we are here to learn them in practice and get benefit of using them.** 23 | **Enjoy Math and Number Theory!** 24 | 25 |
26 | 27 | 28 | ## My Session @ ICPC SCU 29 | - [Basic Math & Number Theory: Part 1](https://www.youtube.com/watch?v=UaVq66jUhyc&t=2552s) 30 | 31 | - [Basic Math & Number Theory: Part 2](https://www.youtube.com/watch?v=SgdE9CN7Fz4) 32 | 33 | ## Useful Materials 34 | 35 | ### Reading Materials 36 | 37 | #### Introduction 38 | - [Introduction to Number Theory](https://davidaltizio.web.illinois.edu/Divisors%20and%20Divisibility%20Overview.pdf) 39 | - [Divisibility Rules and tests (MathWarehouse)](https://www.mathwarehouse.com/arithmetic/numbers/divisibility-rules-and-tests.php) 40 | - [Perfect Squares (Cuemath)](https://www.cuemath.com/algebra/perfect-squares/) 41 | - [Logarithm Basics (Mathinisght)](https://mathinsight.org/logarithm_basics) 42 | - [Binary Exponentiation (CP-Algorithms)](https://cp-algorithms.com/algebra/binary-exp.html) 43 | - [Euclidean Algorithm to find the GCD (CP-Algorithms)](https://cp-algorithms.com/algebra/euclid-algorithm.html) 44 | 45 | - [Fibonacci Numbers (CP-Algorithms)](https://cp-algorithms.com/algebra/fibonacci-numbers.html) 46 | 47 | #### Primes 48 | - [Primality Test | Set 1 (GeeksforGeeks)](https://www.geeksforgeeks.org/primality-test-set-1-introduction-and-school-method/) 49 | - [Sieve of Eratosthenes (GeeksforGeeks)](https://www.geeksforgeeks.org/sieve-of-eratosthenes/) 50 | - [Sieve of Eratosthenes (CP-Algorithms)](https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html) 51 | 52 | #### Modular Arithmetic 53 | - [Modular Arithmetic (GeeksforGeeks)](https://www.geeksforgeeks.org/modular-arithmetic/) 54 | - [Compute an answer under modulo 1e9 + 7 (GeeksforGeeks)](https://www.geeksforgeeks.org/modulo-1097-1000000007/) 55 | - [How to compute n! under modulo p efficiently (GeeksforGeeks)](https://www.geeksforgeeks.org/compute-n-under-modulo-p/) 56 | - [How to compute mod for a big number (GeeksforGeeks)](https://www.geeksforgeeks.org/how-to-compute-mod-of-a-big-number/) 57 | - [How to find the value of y mod 2 raised to the power x efficiently (GeeksforGeeks)](https://www.geeksforgeeks.org/find-value-of-y-mod-2-raised-to-power-x/) 58 | 59 | 60 | ### Video Materials 61 | 62 | #### Introduction 63 | - [Elementary Math (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=Syx2qDjj7TE&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=1) 64 | - [Factorization (Mr.Algorithms)](https://www.youtube.com/watch?v=JS-0DOGrNmo&list=PLR5x_RGTMNNX6KCXeA9Fj-xNLzt9bi3eL&index=9) 65 | - [Factorization (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=-5ApOQDhBtU&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=4) 66 | - [GCD (Mr.Algorithms)](https://www.youtube.com/watch?v=DWaor1rGxog&list=PLR5x_RGTMNNX6KCXeA9Fj-xNLzt9bi3eL&index=15) 67 | - [LCM (Mr.Algorithms)](https://www.youtube.com/watch?v=si-Tk_C0nIQ&list=PLR5x_RGTMNNX6KCXeA9Fj-xNLzt9bi3eL&index=18) 68 | - [Binary Exponentiation (Errichto)](https://www.youtube.com/watch?v=L-Wzglnm4dM&t=101s) 69 | - [Factorial (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=YTLv1fgISPI&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=5) 70 | - [Fibonacci, GCD, LCM, Power (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=YklnFXpq0ZE&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=6) 71 | 72 | #### Primes 73 | - [Prime Factorization (Mr.Algorithms)](https://www.youtube.com/watch?v=O4WljSHt27w&list=PLR5x_RGTMNNX6KCXeA9Fj-xNLzt9bi3eL&index=12) 74 | - [Primes (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=VZBfW08ECgA&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=3) 75 | 76 | #### Modular Arithmetic 77 | - [Modular Arithmetic (Mr.Algorithms)](https://www.youtube.com/watch?v=Scw9LAtuwvg&list=PLR5x_RGTMNNX6KCXeA9Fj-xNLzt9bi3eL&index=2) 78 | - [Modular Arithmetic (Errictho)](https://www.youtube.com/watch?v=-OPohCQqi_E) 79 | - [Modular Arithmetic (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=9sqvjnvuLtY&list=PLPt2dINI2MIY7l5zyFd1W28rei3b-AXaJ&index=2) 80 | 81 | 82 | ## Practice Problems 83 | 84 | - [The last 2 digits (CF - Assiut's sheet)](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/Y) 85 | - [Zara welcomes visitors (CF - Luxor's Marathon)](https://codeforces.com/group/y3RUgysowo/contest/376178/problem/Y) 86 | - [Player and Time (CF - SCU's Contest)](https://codeforces.com/group/p6hc42ieQe/contest/296868/problem/B) 87 | - [Player and Sum (CF - SCU's Contest)](https://codeforces.com/group/p6hc42ieQe/contest/296868/problem/C) 88 | - [Modulo Sum (CF - SCU's Contest)](https://codeforces.com/group/p6hc42ieQe/contest/297904/problem/F) 89 | - [Divisible (CF - Assiut's Sheet)](https://codeforces.com/group/MWSDmqGsZm/contest/223338/problem/M) 90 | - [GCD and LCM (CodeChef)](https://www.codechef.com/problems/FLOW016) 91 | - [Exponentiation (CSES)](https://cses.fi/problemset/task/1095) 92 | - [Big Mod (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=310) 93 | - [Counting Divisors (CSES)](https://cses.fi/problemset/task/1713) 94 | - [Prime Factorization (CF)](https://codeforces.com/problemset/problem/162/C) 95 | - [Div Game (AtCoder)](https://atcoder.jp/contests/abc169/tasks/abc169_d) 96 | - [Common Divisors (CSES)](https://cses.fi/problemset/task/1081) 97 | - [Product 1 Modulo N (CF)](https://codeforces.com/problemset/problem/1514/C) 98 | - [Back to Intermediate (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1714) 99 | - [The 3n + 1 problem](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=36) 100 | - [One Prime (CF - Assiut's Sheet)](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/H) 101 | - [Primes from 1 to n (CF - Assiut's Sheet)](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/J) 102 | - [Finding the Kth Prime (SPOJ)](https://www.spoj.com/problems/TDKPRIME/) 103 | - [Integer Factorization (SPOJ)](https://www.spoj.com/problems/FACT0/) 104 | - [Bubble Sort (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3155) 105 | - [Very Big Perfect Squares (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3178) 106 | - [Numbering Roads (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=2823) 107 | - [Brick Game (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=2986) 108 | - [Perfection (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=318) 109 | - [Digit Counting (UVA)](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3666) 110 | 111 | ## Additional Interesting Links 112 | 113 | - [Guide to Competitive Programming Book (Mathematics Section)](https://link.springer.com/chapter/10.1007/978-3-319-72547-5_11#Sec2) 114 | - [Alcumus (Art of Problem-Solving)](https://artofproblemsolving.com/alcumus/problem) -------------------------------------------------------------------------------- /Binary Search/README.md: -------------------------------------------------------------------------------- 1 | # Binary Search 2 | 3 | Binary search is a fundamental algorithmic technique commonly used in competitive programming. It is a search algorithm that works on sorted arrays or lists by repeatedly dividing the search interval in half. 4 | 5 | ## How it works 6 | 7 | Binary search works by comparing the target value to the middle element of the array. If the target value matches the middle element, the search is successful. Otherwise, the algorithm halves the search interval again and repeats the process until the target value is found or the search interval is empty. 8 | 9 | This algorithm has a run-time complexity of O(log n), which is much faster than linear search (which has a run-time complexity of O(n)). 10 | 11 | ## Implementing Binary Search 12 | 13 | Here's a simple implementation of binary search in Python: 14 | 15 | ``` Python 16 | def binary_search(arr, target): 17 | left, right = 0, len(arr) - 1 18 | while left <= right: 19 | mid = (left + right) // 2 20 | if arr[mid] == target: 21 | return mid 22 | elif arr[mid] < target: 23 | left = mid + 1 24 | else: 25 | right = mid - 1 26 | return -1 27 | 28 | ``` 29 | 30 | ## Applications of Binary Search 31 | 32 | Binary search has many practical applications in computer science and is widely used in various fields. Some common applications of binary search include: 33 | 34 | - Finding elements in a sorted list or array 35 | - Finding the closest match in a sorted list or array 36 | - Counting the number of occurrences of a target value in a sorted list or array 37 | 38 | 39 | Binary search is an essential algorithmic technique that is commonly used in competitive programming. It is a fast and efficient way to search for target values in sorted arrays or lists. Understanding how binary search works and how to implement it is essential for any competitive programmer. 40 | 41 | **And we are here to learn it in practice and get benefit of using it.** 42 | **Enjoy Binary Search!** 43 | 44 | ## My Session @ ICPC SCU 45 | 46 | - [Binary Search](https://www.youtube.com/watch?v=K224kaUPVZc) 47 | 48 | ## Useful Materials 49 | 50 | > I highly recommend starting with CodeForces EDU section 51 | 52 | - [Binary Search (CodeForces EDU)](https://codeforces.com/edu/course/2/lesson/6/1) 53 | 54 | ### Video Materials 55 | 56 | - [Search Techniques - Binary Search (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=2G7RzlxTNPo&list=PLPt2dINI2MIZcJ3kADyFAOKOwzuvT-g7P) 57 | 58 | - [Binary Search turtorial (Errichto)](https://www.youtube.com/watch?v=GU7DpgHINWQ) 59 | 60 | ### Reading Materials 61 | 62 | - [Binary Search (TopCoder) **Highly Recommended**](https://www.topcoder.com/thrive/articles/Binary%20Search) 63 | 64 | - [Binary Search (GeeksforGeeks)](https://www.geeksforgeeks.org/binary-search/) 65 | 66 | - [Binary Search (programiz)](https://www.programiz.com/dsa/binary-search) 67 | 68 | 69 | ## Practice Problems 70 | 71 | - [Binary Search sheet (ICPC SCU)](https://codeforces.com/group/KQlzWufN6x/contests) 72 | 73 | - [Sqrt(X) (LeetCode)](https://leetcode.com/problems/sqrtx/) 74 | 75 | - [Arranging Coins (LeetCode)](https://leetcode.com/problems/arranging-coins/) 76 | 77 | - [Poisoned Dagger (CodeForces)](https://codeforces.com/problemset/problem/1613/C) 78 | 79 | - [Sum of Cubes (CodeForces)](https://codeforces.com/problemset/problem/1490/C) 80 | 81 | - [K-th Not Divisible by n (CodeForces)](https://codeforces.com/problemset/problem/1352/C) 82 | 83 | - [Perfect Team (CodeForces)](https://codeforces.com/problemset/problem/1221/C) 84 | 85 | - [Sport Mafia (CodeForces)](https://codeforces.com/problemset/problem/1195/B) 86 | -------------------------------------------------------------------------------- /Bits Manipulation/README.md: -------------------------------------------------------------------------------- 1 | # Bit Manipulation 2 | 3 | ## Introduction 4 | 5 | Bit manipulation is a technique used to manipulate the bits that make up a binary number. In competitive programming, this technique can be used to solve problems quickly and efficiently. Here, I will introduce you to bit manipulation and how it can be used in competitive programming. 6 | 7 | ## Basic Bitwise Operators 8 | 9 | The following are the basic bitwise operators you need to know: 10 | 11 | 1. AND (`&`): The result of `a & b` is a number where each bit is set to 1 only if the corresponding bits of `a` and `b` are both 1. Otherwise, the bit is set to 0. 12 | 2. OR (`|`): The result of `a | b` is a number where each bit is set to 1 if either the corresponding bit of `a` or `b` is 1. Otherwise, the bit is set to 0. 13 | 3. XOR (`^`): The result of `a ^ b` is a number where each bit is set to 1 if the corresponding bits of `a` and `b` are different. Otherwise, the bit is set to 0. 14 | 4. NOT (`~`): The result of `~a` is a number where each bit is the complement of the corresponding bit in `a`. That is, if the bit in `a` is 0, the bit in the result is 1, and vice versa. 15 | 16 | ## Bitwise Shift Operators 17 | 18 | The following are the bitwise shift operators: 19 | 20 | 1. Left Shift (`<<`): The result of `a << b` is a number where the bits of `a` are shifted left by `b` positions. The leftmost `b` bits are set to 0. 21 | 2. Right Shift (`>>`): The result of `a >> b` is a number where the bits of `a` are shifted right by `b` positions. The rightmost `b` bits are set to 0. 22 | 23 | ## Bit Manipulation Techniques 24 | 25 | Here are some common bit manipulation techniques you can use in competitive programming: 26 | 27 | 1. Setting a bit: To set the `i`th bit of a number `n`, you can use the expression `n |= (1 << i)`. 28 | 2. Clearing a bit: To clear the `i`th bit of a number `n`, you can use the expression `n &= ~(1 << i)`. 29 | 3. Checking if a bit is set: To check if the `i`th bit of a number `n` is set, you can use the expression `n & (1 << i) != 0`. 30 | 4. Counting the number of set bits in a number: To count the number of set bits in a number `n`, you can use the following code snippet: 31 | 32 | ``` Python 33 | count = 0 34 | while n: 35 | count += n & 1 36 | n >>= 1 37 | 38 | ``` 39 | 40 | Bit manipulation is a powerful technique that can be used to solve problems quickly and efficiently in competitive programming. By understanding the basic bitwise operators and bitwise shift operators, as well as common bit manipulation techniques, you will be able to solve problems that would otherwise be difficult or time-consuming to solve. 41 | 42 | **And we are here to learn it in practice and get benefit of using it.** 43 | **Enjoy Bits Manipulation!** 44 | 45 | 46 | ## My Session @ ICPC SCU 47 | 48 | - [Bits Manipulation](https://www.youtube.com/watch?v=fHfFCFYJsGE&t=1s) 49 | 50 | 51 | ### Reading Materials 52 | 53 | - [Bitwise Operators in C/C++ (GeeksforGeeks)](https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/?ref=lbp) 54 | - [Bitwise Hacks for Competitive Programming (GeeksforGeeks)](https://www.geeksforgeeks.org/bitwise-hacks-for-competitive-programming/) 55 | - [Bit Tricks for Competitive Programming (GeeksforGeeks)](https://www.geeksforgeeks.org/bit-tricks-competitive-programming/) 56 | - [Bits Manipulation: Important Tactics (GeeksforGeeks)](https://www.geeksforgeeks.org/bits-manipulation-important-tactics/) 57 | - [Bitwise Algorithms (GeeksforGeeks)](https://www.geeksforgeeks.org/bitwise-algorithms/?ref=shm) 58 | - [Bit Magic Articles (GeeksforGeeks)](https://www.geeksforgeeks.org/basic/bit-magic) 59 | - [How to use bit manipulation to solve problems easily and efficiently (LeetCode)](https://leetcode.com/problems/sum-of-two-integers/discuss/84278/a-summary-how-to-use-bit-manipulation-to-solve-problems-easily-and-efficiently#:~:text=A%20big%20advantage%20of%20bit,for%20some%20dynamic%20programming%20solutions) 60 | 61 | ### Video Materials 62 | 63 | - [Bitwise Operators (Errichto)](https://www.youtube.com/watch?v=xXKL9YBWgCY&list=PLl0KD3g-oDOEbtmoKT5UWZ-0_JbyLnHPZ&index=8) 64 | - [C++ Bitsets in Competitive Programming (Errichto)](https://www.youtube.com/watch?v=jqJ5s077OKo&list=PLl0KD3g-oDOEbtmoKT5UWZ-0_JbyLnHPZ&index=9) 65 | - [Bits (Mostafa Saad)](https://www.youtube.com/watch?v=ldwGf-iVsdU) 66 | 67 | ## Practice problems 68 | 69 | - [ICPC SCU's sheet](https://codeforces.com/group/KQlzWufN6x/contest/376362) 70 | - [Assiut's sheet](https://codeforces.com/group/u3Ii79X3NY/contest/274952) -------------------------------------------------------------------------------- /Data Types & Conditions/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Data Types and Conditions 3 | 4 | ## Data Types 5 | 6 | In competitive programming, it is essential to know the different data types and their limits. The following are the most commonly used data types: 7 | 8 | - **Integer**: It is a whole number (positive, negative, or zero) without any decimal point. In C++, the range of an integer is from -231 to 231-1. In Python, the range is not defined, and the integer can be of any length. 9 | - **Long long**: It is an extended data type in C++ used when the range of an integer exceeds the limit of int. In C++, the range of a long long is from -263 to 263-1. 10 | - **Char**: It is a data type that stores a single character. In C++, it is represented by single quotes. For example, 'a', 'b', 'c'. 11 | - **String**: It is a data type that stores a sequence of characters. In C++, it is represented by double quotes. For example, "Hello". 12 | - **Boolean**: It is a data type that can have only two values: true or false. 13 | 14 | ## Conditions 15 | 16 | Conditions are used to make decisions in a program. In competitive programming, some of the commonly used conditions are: 17 | 18 | - **If-else**: It is used to execute a block of code if a condition is true and another if it is false. 19 | - **Switch**: It is used to execute different blocks of code based on different conditions. 20 | - **Ternary operator**: It is a shorthand version of the if-else statement. It is used to assign a value based on a condition. 21 | 22 | Understanding data types and conditions is essential in competitive programming as it helps in writing optimized and efficient code. 23 | 24 | 25 | 26 | **And we are here to learn them in practice and get benefit of using them.** 27 | **Enjoy Data Types and Conditions!** 28 | 29 |
30 | 31 | ## My Session @ ICPC SCU 32 | 33 | - [Data Types & Conditions](https://www.youtube.com/watch?v=Ua_O0tLhtF8) 34 | 35 | 36 | ## Useful Materials 37 | 38 | ### Video Materials 39 | 40 | - [Introduction to Programming (Adel Nasim)](https://www.youtube.com/watch?v=z1FdInL8sjg&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=1) 41 | - [Writing your first program in C++ (Adel Nasim)](https://www.youtube.com/watch?v=xo1R1nYM4aw&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=2) 42 | - [Escape Sequence (Adel Nasim)](https://www.youtube.com/watch?v=pw7rTydaSYs&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=3) 43 | - [Variabls vs Data type (Adel Nasim)](https://www.youtube.com/watch?v=FBjOHTuOIqo&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=4) 44 | - [Priorities & Calculations in C++ (Adel Nasim)](https://www.youtube.com/watch?v=0rYYaXlEiAY&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=5) 45 | - [Basic Arithmetic & Casting (Adel Nasim)](https://www.youtube.com/watch?v=UpBYeNTwgbs&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=6) 46 | - [Prefix, Postfix, and Compound assignment (Adel Nasim)](https://www.youtube.com/watch?v=6XjgNR5Cw48&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=7) 47 | - [Variable Scope (Local vs Global) (Adel Nasim)](https://www.youtube.com/watch?v=Pkl5iFCNNs4&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=8) 48 | - [Selection Statement (Adel Nasim)](https://www.youtube.com/watch?v=F56Bo4I0GhA&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=9) 49 | - [Logical Operators (Adel Nasim)](https://www.youtube.com/watch?v=taov2H_-nlU&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=10) 50 | - [Switch Statement (Adel Nasim)](https://www.youtube.com/watch?v=-MTeqw7gZf0&list=PLCInYL3l2AajFAiw4s1U4QbGszcQ-rAb3&index=11) 51 | - [Errors (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=I11mfEdfh-4&ab_channel=ArabicCompetitiveProgramming) 52 | - [Division & Modulus (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=jJVaDl_dePk&ab_channel=ArabicCompetitiveProgramming) 53 | 54 | 55 | ### Reading Materials 56 | 57 | - [Introduction to C++ programming language (GeeksforGeeks)](https://www.geeksforgeeks.org/introduction-to-c-programming-language/?ref=lbp) 58 | - [C++ programming basics (GeeksforGeeks)](https://www.geeksforgeeks.org/c-programming-basics/?ref=lbp) 59 | - [C++ Data Types (GeeksforGeeks)](https://www.geeksforgeeks.org/c-data-types/?ref=lbp) 60 | - [Variables in C++ (GeeksforGeeks)](https://www.geeksforgeeks.org/variables-in-c/?ref=lbp) 61 | - [Decision Making in C++ (GeeksforGeeks)](https://www.geeksforgeeks.org/decision-making-c-c-else-nested-else/?ref=lbp) 62 | 63 | ## Practice Problems 64 | - [Data Types & Conditions Sheet (ICPC SCU)](https://codeforces.com/group/n3sTiYtHxI/contest/348729) -------------------------------------------------------------------------------- /Dynamic Programming/Introduction/Coin Change Problem Discussion.md: -------------------------------------------------------------------------------- 1 | [Coin Change (LeetCode)](https://leetcode.com/problems/coin-change/description/) 2 | 3 | ## Here, we will discuss and explain solutions of Coin Change problem: 4 | 5 | 6 | ### Problem Statement: 7 | > You are given an integer array representing coins of different denominations and an integer representing a total amount of money. 8 | You are required to return the fewest number of coins that you need to make up that total amount. And if there is no combination of coins that make up that total amount, return -1 9 | 10 | 11 | During the session, there were 3 suggested solution by 3 different people, and we didn't show which of the solutions would work and what wouldn't, so let's do it now. 12 | 13 | 14 | ### Solution 1 (Wrong Answer): 15 | 16 | ```C++ 17 | class Solution { 18 | public: 19 | 20 | vector memo; 21 | 22 | int dp(int val, vector& coins){ 23 | if(not val){ 24 | return 0; 25 | } 26 | int& ret = memo[val]; 27 | if(~ret){ 28 | return ret; 29 | } 30 | ret = int(1e7); 31 | 32 | for(auto& coin : coins){ 33 | ret = min(ret, val / coin + dp(val % coin, coins)); 34 | } 35 | return ret; 36 | } 37 | 38 | int coinChange(vector& coins, int amount) { 39 | memo.assign(amount + 5, -1); 40 | int ans = dp(amount, coins); 41 | if(ans > amount) 42 | ans = -1; 43 | return ans; 44 | } 45 | }; 46 | ``` 47 | 48 | This solution is wrong becuase the idea of taking modulo means that each time we decide to pick a coin with some value, we're taking as many coins as we can, and then calling the function with the remainder after these operations. 49 | 50 | For example: if we currently have the total amount equals to 5, and we decide to choose a coin with value 2, we have to take 2 coins and make a call with the remainder which equals to 1 (while this may not be the optimal answer and we need to take only one coin with value 2) 51 | 52 | 53 | ### Solution 2 (Time Limit Exceeded): 54 | 55 | ```C++ 56 | 57 | class Solution { 58 | public: 59 | 60 | vector memo; 61 | 62 | int dp(int val, vector& coins){ 63 | if(not val){ 64 | return not val ? 0 : int(1e7); 65 | } 66 | int& ret = memo[val]; 67 | if(~ret){ 68 | return ret; 69 | } 70 | ret = int(1e7); 71 | 72 | for(int idx = 0; idx < coins.size(); idx++){ 73 | for(int i = 1; ; i++){ 74 | if(i * coins[idx] > val) 75 | break; 76 | ret = min(ret, i + dp(val - coins[idx] * i, coins)); 77 | } 78 | } 79 | return ret; 80 | } 81 | 82 | int coinChange(vector& coins, int amount) { 83 | memo.assign(amount + 5, -1); 84 | int ans = dp(amount, coins); 85 | if(ans > amount) 86 | ans = -1; 87 | return ans; 88 | } 89 | }; 90 | 91 | ``` 92 | 93 | This solution gives us a correct answer, but exceeds the time limit for the problem because of the internal loop which checks for the number of coins we need to pick with this value. After many such calls with big values of Total Amount and small values of Coins, this will exceed the limit and our solution will not pass. 94 | 95 | 96 | ### Solution 3 (Accepted): 97 | 98 | ```C++ 99 | 100 | class Solution { 101 | public: 102 | 103 | vector> memo; 104 | 105 | int dp(int idx, int value, vector& coins){ 106 | if(value <= 0 or idx >= coins.size()){ 107 | return not value ? 0 : int(1e7); 108 | } 109 | 110 | int& ret = memo[idx][value]; 111 | if(~ret){ 112 | return ret; 113 | } 114 | ret = int(1e7); 115 | 116 | ret = dp(idx + 1, value, coins); 117 | ret = min(ret, 1 + dp(idx + 1, value - coins[idx], coins)); 118 | ret = min(ret, 1 + dp(idx, value - coins[idx], coins)); 119 | 120 | return ret; 121 | } 122 | 123 | int coinChange(vector& coins, int amount) { 124 | memo.assign(coins.size(), vector(amount + 5, -1)); 125 | int ans = dp(0, amount, coins); 126 | if(ans > amount) 127 | ans = -1; 128 | return ans; 129 | } 130 | }; 131 | 132 | ``` 133 | 134 | This solution is correct and doesn't exceed the time limit. Here, we are trying 3 different possibilities for each coin: 135 | 136 | 1. We can leave the coins having the current values and move to the next coin without changing our value (excluding coin[idx] from the solution) 137 | 138 | 2. We can pick one of the coins having the current value only this time, change total value to **value - coins[idx]**, and then proceed to the next value of coins 139 | 140 | 3. We can pick one of the coins having the current value, change the total value to **value - coins[idx]**, and then try to pick another coin with same value (we don't change the index) 141 | 142 | This will implement the idea of the previous solution without making unnecessary loops that may cause TLE. 143 | 144 | 145 | ### Additional Solution (Accepted + Better Memory): 146 | 147 | ```C++ 148 | class Solution { 149 | public: 150 | 151 | vector memo; 152 | 153 | int dp(int val, vector& coins){ 154 | if(val <= 0){ 155 | return not val ? 0 : int(1e7); 156 | } 157 | int& ret = memo[val]; 158 | if(~ret){ 159 | return ret; 160 | } 161 | ret = int(1e7); 162 | 163 | for(int idx = 0; idx < coins.size(); idx++){ 164 | ret = min(ret, 1 + dp(val - coins[idx], coins)); 165 | } 166 | return ret; 167 | } 168 | 169 | int coinChange(vector& coins, int amount) { 170 | memo.assign(amount + 5, -1); 171 | int ans = dp(amount, coins); 172 | if(ans > amount) 173 | ans = -1; 174 | return ans; 175 | } 176 | }; 177 | ``` 178 | 179 | This solution is changing the prespective we look at the solution from. Instead of finding the best answer for the current value starting from a particular coin, we are trying to find the best answer for the current value and discarding index's dimension. 180 | For each call, we are iterating over the set of coins we have and trying to pick a suitable coin for current Total Amount, and then proceeding to the next resulting value after picking this coin. -------------------------------------------------------------------------------- /Dynamic Programming/Introduction/README.md: -------------------------------------------------------------------------------- 1 | # Dynamic Programming: Introduction 2 | 3 | As we said before, Dynamic programming is a method of solving complex problems by breaking them down into simpler subproblems. 4 | 5 | It is a powerful technique for optimizing complex problems by decomposing them into subproblems that can be solved independently and then combining the solutions of these subproblems to get the solution to the original problem. Also, it can be used to solve optimization problems, such as finding the shortest path between two points or the most efficient way to allocate resources. 6 | 7 | It is also used to solve problems where the same subproblem is solved multiple times, such as finding the most efficient way to turn a knapsack of items into a profit. Dynamic programming can also be used to solve recursive problems, such as finding the nth number in a Fibonacci sequence. 8 | 9 |
10 | 11 | ## My Session @ ICPC SCU 12 | 13 | > - You can start from **8:00** if you like to skip the introduction 14 | > - You can find my explanation, solution, and discussion for coin change problem discussed in the session [here](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/blob/master/Dynamic%20Programming/Introduction/Coin%20Change%20Problem%20Discussion.md) (because I think I didn't explain it in the right way) 15 | - [Dynamic Programming](https://www.youtube.com/watch?v=5zyMGXmYDJg&lc=UgxSFnz0WBTKLQluvNx4AaABAg) 16 | 17 | 18 | ## Useful Materials 19 | 20 | ### Video Materials 21 | 22 | - [Dynamic Programming - Introduction - Part 1 (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=gFdP6X4CyKU&list=PLPt2dINI2MIattDutu7IOAMlUuLeN8k2p&index=1) 23 | 24 | - [Dynamic Programming - Introduction - Part 2 (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=1j3srLj-C5Q&list=PLPt2dINI2MIattDutu7IOAMlUuLeN8k2p&index=2) 25 | 26 | - [Dynamic Programming: Lecture 1 (Errichto)](https://www.youtube.com/watch?v=YBSt1jYwVfU&list=PLl0KD3g-oDOGJUdmhFk19LaPgrfmAGQfo&index=1) 27 | 28 | - [Dynamic Programming: Lecture 2 (Errichto)](https://www.youtube.com/watch?v=1mtvm2ubHCY&list=PLl0KD3g-oDOGJUdmhFk19LaPgrfmAGQfo&index=2) 29 | 30 | - [Dynamic Programming: Lecture 3 (Errichto)](https://www.youtube.com/watch?v=pwpOC1dph6U&list=PLl0KD3g-oDOGJUdmhFk19LaPgrfmAGQfo&index=3) 31 | 32 | 33 | ### Reading Materials 34 | 35 | - [What is Dynamic Programming (Upwork)](https://www.upwork.com/resources/what-is-dynamic-programming) 36 | 37 | - [Dynamic Programming: Basic Concepts (GeeksforGeeks)](https://www.geeksforgeeks.org/dynamic-programming/?ref=ghm#concepts) 38 | 39 | ## Practice Materials 40 | 41 | - [Dynamic Programming: Introduction (USACO Guide)](https://usaco.guide/gold/intro-dp?lang=cpp) **Highly Recommended** 42 | 43 | - [Dynamic Programming: Basic Problems (GeeksforGeeks)](https://www.geeksforgeeks.org/dynamic-programming/?ref=ghm#basicProblems) 44 | 45 | - [CSES: Dynamic Programming Section](https://cses.fi/problemset/) **Highly Recommended** -------------------------------------------------------------------------------- /Dynamic Programming/README.md: -------------------------------------------------------------------------------- 1 | # Dynamic Programming 2 | 3 | Dynamic programming is an algorithmic technique that is widely used in competitive programming. It is a method for solving problems by breaking them down into smaller subproblems and solving each subproblem only once. The solutions to the subproblems are then combined to give the solution to the original problem. In this document, we will discuss the basics of dynamic programming and provide code snippets to explain its usage. 4 | 5 | ## Basic Concept 6 | 7 | The basic concept of dynamic programming is to solve a problem by breaking it down into smaller subproblems and solving each subproblem only once. The solutions to the subproblems are then combined to give the solution to the original problem. 8 | 9 | Dynamic programming is used when a problem has overlapping subproblems and optimal substructure. Overlapping subproblems refer to situations where the same subproblems need to be solved multiple times. Optimal substructure means that the solution to a problem can be obtained by combining the solutions to its subproblems. 10 | 11 | ### Fibonacci Series 12 | 13 | The Fibonacci series is a classic example of a problem that can be solved using dynamic programming. The Fibonacci sequence is defined as follows: 14 | 15 | ``` Python 16 | F(0) = 0 17 | F(1) = 1 18 | F(n) = F(n - 1) + F(n - 2) (for n > 1) 19 | 20 | ``` 21 | 22 | Here is an implementation of the Fibonacci series using dynamic programming: 23 | 24 | ``` Python 25 | def fib(n): 26 | if n == 0: 27 | return 0 28 | elif n == 1: 29 | return 1 30 | else: 31 | fib_arr = [0] * (n + 1) 32 | fib_arr[0] = 0 33 | fib_arr[1] = 1 34 | for i in range(2, n + 1): 35 | fib_arr[i] = fib_arr[i - 1] + fib_arr[i - 2] 36 | return fib_arr[n] 37 | 38 | ``` 39 | 40 | ### Longest Common Subsequence 41 | 42 | The longest common subsequence problem is another classic example of a problem that can be solved using dynamic programming. The problem is defined as follows: 43 | 44 | Given two sequences, find the longest subsequence present in both of them. 45 | 46 | Here is an implementation of the longest common subsequence problem using dynamic programming: 47 | 48 | ``` Python 49 | def lcs(X, Y): 50 | m = len(X) 51 | n = len(Y) 52 | L = [[0 for x in range(n + 1)] for y in range(m + 1)] 53 | for i in range(m + 1): 54 | for j in range(n + 1): 55 | if i == 0 or j == 0: 56 | L[i][j] = 0 57 | elif X[i - 1] == Y[j - 1]: 58 | L[i][j] = L[i - 1][j - 1] + 1 59 | else: 60 | L[i][j] = max(L[i - 1][j], L[i][j - 1]) 61 | return L[m][n] 62 | 63 | ``` 64 | 65 | Dynamic programming is a powerful technique that can be used to solve a wide range of problems in competitive programming. By breaking down problems into smaller subproblems and solving each subproblem only once, dynamic programming algorithms can be used to improve the efficiency and speed of code. The code snippets provided in this document serve as a starting point for understanding and implementing dynamic programming algorithms. 66 | 67 | 68 | **And we are here to learn it in practice and get benefit of using it.** 69 | **Enjoy Dynamic Programming!** 70 | 71 | ## Dynamic Programming Topics Covered So Far 72 | - [Dynamic Programming: Introduction](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Dynamic%20Programming/Introduction) 73 | - [Dynamic Programming: Subsets, Counting, and Longest Increasing Subsequence (LIS)](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Dynamic%20Programming/Subsets%2C%20LIS%2C%20Counting) -------------------------------------------------------------------------------- /Dynamic Programming/Subsets, LIS, Counting/README.md: -------------------------------------------------------------------------------- 1 | ## Longest Increasing Subsequence 2 | 3 | The Longest Increasing Subsequence (LIS) is a classical problem in computer science and dynamic programming. Given an array of integers, we want to find the longest increasing subsequence within it. For example, given the array `[10, 9, 2, 5, 3, 7, 101, 18]`, the LIS is `[2, 3, 7, 101]` with length 4. 4 | 5 | ### Approach 6 | 7 | To solve the LIS problem, we can use dynamic programming. We create an array `dp` of the same length as the input array, where `dp[i]` represents the length of the LIS ending at `nums[i]`. We initialize `dp[i]` to 1 for all `i`, since the LIS of a single element is just that element itself. We then iterate through the array, updating `dp[i]` for each element `nums[i]` by finding the maximum value of `dp[j] + 1` for all `j` such that `nums[j] < nums[i]`. This gives us the length of the LIS ending at `nums[i]`. Finally, we return the maximum value in `dp`. 8 | 9 | ### Code 10 | 11 | ``` Python 12 | def lengthOfLIS(nums: List[int]) -> int: 13 | n = len(nums) 14 | dp = [1] * n 15 | for i in range(1, n): 16 | for j in range(i): 17 | if nums[j] < nums[i]: 18 | dp[i] = max(dp[i], dp[j] + 1) 19 | return max(dp) 20 | 21 | ``` 22 | 23 | ***We Discussed more optimizations and applied it during the session*** 24 | 25 | ## Counting 26 | 27 | Counting problems are a common type of problem in computer science and dynamic programming. Given a set of objects, we want to count the number of ways we can select a subset of those objects that satisfy certain conditions. 28 | 29 | ### Approach 30 | 31 | To solve counting problems, we can use dynamic programming. We create a table `dp` where `dp[i][j]` represents the number of ways to select a subset of the first `i` objects that satisfies the given condition(s) and has size `j`. We initialize `dp[i][0]` to 1 for all `i`, since the empty set is always a valid subset. We then iterate through the objects, updating `dp[i][j]` for each `i` and `j` by summing up the values of `dp[i-1][j-k]` for all `k` such that the subset of the first `i-1` objects has size `j-k` and satisfies the given condition(s) with the `i`-th object. This gives us the final answer, which is the sum of `dp[n][j]` for all `j` that satisfy the given condition(s). 32 | 33 | ### Code 34 | 35 | ``` Python 36 | def countSubsets(objects: List[object], condition: Callable[[Set[object]], bool]) -> int: 37 | n = len(objects) 38 | dp = [[0] * (n+1) for _ in range(n+1)] 39 | for i in range(n+1): 40 | dp[i][0] = 1 41 | for i in range(1, n+1): 42 | for j in range(1, n+1): 43 | dp[i][j] = dp[i - 1][j] 44 | if condition(set(objects[:i])) and j >= 1: 45 | dp[i][j] += dp[i - 1][j - 1] 46 | ans = 0 47 | for j in range(n+1): 48 | if condition(set(objects[:n])) and j <= len(objects): 49 | ans += dp[n][j] 50 | return ans 51 | 52 | ``` 53 | 54 | # Knapsack Problem Variants 55 | 56 | The Knapsack Problem is a classic problem in computer science and dynamic programming. Given a set of items, each with a weight and a value, and a knapsack with a maximum weight capacity, we want to find the most valuable subset of the items that can fit into the knapsack. 57 | 58 | In this readme, we will explore some variants of the Knapsack Problem and how to solve them using dynamic programming. 59 | 60 | ## 0/1 Knapsack Problem 61 | 62 | In the 0/1 Knapsack Problem, we are only allowed to take one instance of each item. The problem can be solved using dynamic programming. We create a table `dp` where `dp[i][j]` represents the maximum value that can be obtained using the first `i` items and with a knapsack of capacity `j`. We initialize `dp[i][0]` and `dp[0][j]` to 0 for all `i` and `j`, since we can't take any items if the knapsack has no capacity, and we can't get any value if there are no items. We then iterate through the items, updating `dp[i][j]` for each `i` and `j` by taking the maximum of `dp[i-1][j]` (if we don't take the `i`-th item) and `dp[i-1][j-w[i]] + v[i]` (if we do take the `i`-th item), where `w[i]` is the weight of the `i`-th item and `v[i]` is its value. The final answer is `dp[n][W]`, where `n` is the number of items and `W` is the maximum capacity of the knapsack. 63 | 64 | ### Code 65 | 66 | ``` Python 67 | def knapsack01(W: int, wt: List[int], val: List[int], n: int) -> int: 68 | dp = [[0 for i in range(W + 1)] for j in range(n + 1)] 69 | for i in range(n + 1): 70 | for w in range(W + 1): 71 | if i == 0 or w == 0: 72 | dp[i][w] = 0 73 | elif wt[i - 1] <= w: 74 | dp[i][w] = max(val[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]) 75 | else: 76 | dp[i][w] = dp[i - 1][w] 77 | return dp[n][W] 78 | 79 | ``` 80 | 81 | ## Other knapsack problem variants we didn't discuss in the session: 82 | 83 | ## Fractional Knapsack Problem (Greedy Problem) 84 | 85 | In the Fractional Knapsack Problem, we are allowed to take fractional amounts of each item. The problem can be solved using a greedy algorithm. We first calculate the value per unit weight for each item, and then sort the items in non-increasing order of value per unit weight. We then take as much of each item as possible, starting with the item with the highest value per unit weight, until the knapsack is full. 86 | 87 | ### Code 88 | 89 | ``` Python 90 | def fractional_knapsack(W: int, wt: List[int], val: List[int], n: int) -> float: 91 | items = list(zip(wt, val)) 92 | items = sorted(items, key=lambda x: x[1] / x[0], reverse=True) 93 | max_val = 0 94 | for item in items: 95 | if W >= item[0]: 96 | max_val += item[1] 97 | W -= item[0] 98 | else: 99 | max_val += item[1] * (W / item[0]) 100 | break 101 | return max_val 102 | 103 | ``` 104 | 105 | ## Bounded Knapsack Problem 106 | 107 | In the Bounded Knapsack Problem, we are allowed to take a limited number of instances of each item. The problem can be solved using dynamic programming. We create a table `dp` where `dp[i][j]` represents the maximum value that can be obtained using the first `i` items and with a knapsack of capacity `j`. We initialize `dp[i][0]` to 0 for all `i`, since we can't take any items if the knapsack has no capacity. We then iterate through each item, updating `dp[i][j]` for each `i` and `j` by taking the maximum of `dp[i-1][j-k*w[i]] + k*v[i]` for all `k` between 0 and the maximum number of instances of the `i`-th item, where `w[i]` is the weight of the `i`-th item and `v[i]` is its value. The final answer is `dp[n][W]`, where `n` is the number of items and `W` is the maximum capacity of the knapsack. 108 | 109 | ### Code 110 | 111 | ``` Python 112 | def knapsack_bounded(W: int, wt: List[int], val: List[int], n: int, limit: List[int]) -> int: 113 | dp = [[0 for i in range(W + 1)] for j in range(n + 1)] 114 | for i in range(n + 1): 115 | for w in range(W + 1): 116 | if i == 0 or w == 0: 117 | dp[i][w] = 0 118 | else: 119 | dp[i][w] = dp[i - 1][w] 120 | for k in range(1, limit[i - 1]+1): 121 | if wt[i - 1]*k <= w: 122 | dp[i][w] = max(dp[i][w], dp[i - 1][w - k * wt[i - 1]] + k * val[i - 1]) 123 | return dp[n][W] 124 | 125 | ``` 126 | 127 | ## Multiple Knapsack Problem 128 | 129 | In the Multiple Knapsack Problem, we have multiple knapsacks with different weight capacities, and we want to maximize the total value of the items we can take across all the knapsacks. The problem can be solved using dynamic programming. We create a table `dp` where `dp[i][j]` represents the maximum value that can be obtained using the first `i` items and with a total weight of `j` across all the knapsacks. We initialize `dp[i][0]` to 0 for all `i`, since we can't take any items if the total weight is 0. We then iterate through each item, updating `dp[i][j]` for each `i` and `j` by taking the maximum of `dp[i-1][j-k*w[i]] + k*v[i]` for all `k` between 0 and the maximum number of instances of the `i`-th item that can fit into the knapsacks with a total weight of `j`, where `w[i]` is the weight of the `i`-th item and `v[i]` is its value. The final answer is the maximum value in `dp[n][W]`, where `n` is the number of items and `W` is the total weight capacity of all the knapsacks. 130 | 131 | ### Code 132 | 133 | ``` Python 134 | def multiple_knapsack(W: List[int], wt: List[int], val: List[int], n: int) -> int: 135 | dp = [[0 for i in range(sum(W) + 1)] for j in range(n+1)] 136 | for i in range(n+1): 137 | for w in range(sum(W)+1): 138 | if i == 0 or w == 0: 139 | dp[i][w] = 0 140 | else: 141 | dp[i][w] = dp[i - 1][w] 142 | for k in range(1, W[i-1]+1): 143 | if wt[i - 1] * k <= w: 144 | dp[i][w] = max(dp[i][w], dp[i - 1][w - k * wt[i - 1]] + k * val[i - 1]) 145 | return dp[n][sum(W)] 146 | 147 | ``` 148 | 149 | 150 | ## My Session @ ICPC SCU 151 | 152 | - [Dynamic Programming: Subsets - Counting - LIS](https://www.youtube.com/watch?v=VLmp4bXaLto) 153 | 154 | ## Useful Materials 155 | 156 | ### Video Materials 157 | 158 | - [Dynamic Programming - Subset Style (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=vAqaki1BhS0&list=PLPt2dINI2MIattDutu7IOAMlUuLeN8k2p&index=3) 159 | - [Dynamic Programming - Counting (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=lE09Ss_Sy0A&list=PLPt2dINI2MIattDutu7IOAMlUuLeN8k2p&index=8) 160 | - [Dynamic Programming | Set 3 (Longest Increasing Subsequence) | GeeksforGeeks](https://youtu.be/Ns4LCeeOFS4) 161 | - [Longest Common Subsequence (LCS) - Recursion and Dynamic Programming (Abdul Bari)](https://youtu.be/sSno9rV8Rhg) 162 | 163 | 164 | ### Reading Materials 165 | 166 | - [Dynamic Programming: Knapsack [Resources and Tutorial] (USACO)](https://usaco.guide/gold/knapsack?lang=cpp) 167 | - [Dynamic Programming: Longest Increasing Subsequence (USACO)](https://usaco.guide/gold/lis?lang=cpp) 168 | - [Longest Increasing Subsequence (CP-Algorithms)](https://cp-algorithms.com/sequences/longest_increasing_subsequence.html) ***Highly Recommended*** 169 | 170 | ## Practice 171 | 172 | - ***SOLVE AS MANY PROBLEMS AS YOU CAN FROM USACO*** 173 | - You can find here many useful problems: 174 | - [Assiut's Sheet I](https://vjudge.net/contest/463551) 175 | - [Assiut's Sheet II](https://vjudge.net/contest/463553) -------------------------------------------------------------------------------- /Graph Theory/Introduction/README.md: -------------------------------------------------------------------------------- 1 | # Graph Theory: Introduction 2 | 3 | As mentioned previously, there is much to learn about graph theory. In this section, we will explore the fundamental concepts of graph theory and take our first steps in this interesting topic. This introduction is divided into two parts, or sessions. 4 | 5 | **The first session** covers the basic terminology of graph theory, theoretical definitions, basic graph representations, and the idea and implementation of the two fundamental graph traversal algorithms: Depth-First Search (DFS) and Breadth-First Search (BFS). 6 | 7 | **The second session** covers the implementation of standard introductory graph theory problems and tasks, including but not limited to: topological sorting, counting and finding connected components, finding the shortest path from single or multiple sources to all other nodes in the graph, queries to determine if nodes are connected, validating trees, finding and restoring cycles, and checking the bipartiteness of the graph. 8 | 9 | ## My Session @ ICPC SCU 10 | 11 | ### First Part 12 | - [Graph Theory: Introduction](https://www.youtube.com/watch?v=E1fcUDrt4rE&t=4s&ab_channel=AhmedGamal) 13 | 14 | ### Second Part 15 | - Coming Soon .. 16 | 17 | ## Reading Materials 18 | > HIghly Recommended 19 | 20 | - [Breadth-First Search (BFS) (CP-Algorithms)](https://cp-algorithms.com/graph/breadth-first-search.html) 21 | - [Depth-First Search (DFS) (CP-Algorithms)](https://cp-algorithms.com/graph/depth-first-search.html) 22 | - [Finding Connected Components (CP-Algorithms)](https://cp-algorithms.com/graph/search-for-connected-components.html) 23 | - [0-1 BFS (CP-Algorithms)](https://cp-algorithms.com/graph/01_bfs.html) 24 | - [Finding Cycles and Checking for Acyclicity (CP-Algorithms)](https://cp-algorithms.com/graph/finding-cycle.html) 25 | - [Toplogical Sorting (CP-Algorithms)](https://cp-algorithms.com/graph/topological-sort.html) 26 | - [Bipartite Graph Check (CP-Algorithms)](https://cp-algorithms.com/graph/bipartite-check.html) 27 | 28 | ## Video Materials 29 | 30 | 31 | - [Graph Theory Algorithms (William Fiset)](https://youtu.be/DgXR2OWQnLc) 32 | - [Graph Theory Introduction (William Fiset)](https://youtu.be/eQA-m22wjTQ) 33 | - [Overview of Algorithms in Graph Theory (William Fiset)](https://youtu.be/87X57ldq1ok) 34 | - [Depth First Search Algorithm (William Fiset)](https://youtu.be/7fujbpJ0LB4) 35 | - [Breadth First Search Algorithm (william Fiset)](https://youtu.be/oDqjPvD54Ss) 36 | - [Breadth First Search Grid Shortest Path (William Fiset)](https://youtu.be/KiCBXu4P-2Y) 37 | - [Toplogical Sort Algorithm (William Fiset)](https://youtu.be/eL-KzMXSXXI) 38 | - [Topological Sort | Kahn's Algorithm (William Fiset)](https://youtu.be/cIBFEhD77b4) 39 | - [Graph Theory - Introduction (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=jzfcfQVBtKA&ab_channel=ArabicCompetitiveProgramming) 40 | - [Graph Theory - DFS (Dr. Mostafa Saad)](https://youtu.be/9DP0X2xlPCo) 41 | - [Graph Theory - BFS (Dr. Mostafa Saad)](https://youtu.be/COB1GHq0YwY) 42 | 43 | ## Practice Problems 44 | 45 | - [Graph Representation (Assiut's Sheets)](https://vjudge.net/contest/463557) 46 | - [DFS, BFS: Sheet 1 (Assiut's Sheets)](https://vjudge.net/contest/463558) 47 | - [DFS, BFS: Sheet 2 (Assiut's Sheets)](https://vjudge.net/contest/463559) -------------------------------------------------------------------------------- /Graph Theory/README.md: -------------------------------------------------------------------------------- 1 | # Graph Theory 2 | 3 | Graph theory is a very important topic in competitive programming. It is the study of graphs, which are mathematical structures used to model pairwise relations between objects. In computer science, graphs are used to represent networks of communication, data organization, computational devices, the flow of computation, among others. Graphs have a wide variety of applications in computer science, and understanding them is crucial for success in competitive programming. 4 | 5 | ## Basic Graph Terminology 6 | 7 | Before diving into graph theory algorithms and implementations, it's important to understand the basic graph terminology. This terminology provides the foundation for working with graphs. 8 | 9 | - **Vertex (Node):** A data object that represents a point in the graph. It is usually represented by a circle. Vertices are the building blocks of graphs. 10 | - **Edge:** A connection between two vertices. It is usually represented by a line. Edges are the links that connect vertices in a graph. 11 | - **Directed Graph:** A graph where edges have a direction. The edges are represented by arrows pointing from one vertex to another. Directed graphs are used in many applications, such as representing the flow of data or traffic. 12 | - **Undirected Graph:** A graph where edges do not have a direction. The edges are represented by lines connecting two vertices. Undirected graphs are simpler than directed graphs, but they are still quite useful. 13 | - **Weighted Graph:** A graph where edges have a weight or cost associated with them. Weighted graphs are used to model many real-world problems, such as the shortest path between two points in a network. 14 | - **Degree:** The number of edges that are connected to a vertex. The degree of a vertex is an important characteristic of a graph. 15 | 16 | ## Graph Implementation 17 | 18 | There are several ways to implement a graph in competitive programming. One common way is to use an adjacency matrix. An adjacency matrix is a two-dimensional array where each row and column represents a vertex, and the entries represent the edges between them. If the graph is weighted, the entries can represent the weights of the edges. Using an adjacency matrix to represent a graph has some advantages, such as constant-time edge lookup and easy graph traversal. 19 | 20 | ```cpp 21 | const int MAXN = 1000; // Maximum number of vertices 22 | int adjMatrix[MAXN][MAXN]; 23 | 24 | void addEdge(int u, int v, int w) { 25 | adjMatrix[u][v] = w; 26 | // For an undirected graph, add the following line 27 | // adjMatrix[v][u] = w; 28 | } 29 | 30 | ``` 31 | 32 | Another way to implement a graph is to use an adjacency list. An adjacency list is an array of linked lists, where each element represents a vertex, and the linked list contains the vertices that are connected to it. If the graph is weighted, the linked list can contain pairs of vertices and their corresponding weights. Using an adjacency list to represent a graph has some advantages, such as efficient memory usage and easy addition and removal of edges. 33 | 34 | ```cpp 35 | const int MAXN = 1000; // Maximum number of vertices 36 | vector> adjList[MAXN]; 37 | 38 | void addEdge(int u, int v, int w) { 39 | adjList[u].push_back({v, w}); 40 | // For an undirected graph, add the following line 41 | // adjList[v].push_back({u, w}); 42 | } 43 | 44 | ``` 45 | 46 | ## Is that everything? 47 | - There's much more to learn about graph theory, and that's precisely what we're here to do together. Explore the sessions, reading and watching materials, and practice problems to fill in the gaps in your understanding of the topic, and acquire new skills and creative solutions to implement your ideas. 48 | 49 | 50 | ## Graph Theory Topics Covered So Far 51 | 52 | - [Introduction to Graph Theory](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Graph%20Theory/Introduction) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to Competitive Programming Sessions 2 | 3 | This repository contains recorded sessions, detailed explanations, and practice problems for various topics in competitive programming. With this resource, you can improve your problem-solving skills and become a better competitive programmer. The materials provided in this repository are designed to help you understand the concepts and teach you how to apply them to solve problems. 4 | 5 | ## **Topics Covered** 6 | 7 | The following topics are covered extensively in this repository: 8 | 9 | - [Time Complexity](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Time%20Complexity) 10 | - [Arrays](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Arrays) 11 | - [Data Types and Conditions](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Data%20Types%20%26%20Conditions) 12 | - [Basic Math and Number Theory](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Basic%20Math%20%26%20Number%20Theory) 13 | - [Two Pointers](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Two%20Pointers) 14 | - [Binary Search](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Binary%20Search) 15 | - [Bits Manipulation](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Bits%20Manipulation) 16 | - [Recursion and Backtracking](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Recursion%20%26%20Backtracking) 17 | 18 | - [Dynamic Programming](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Dynamic%20Programming) 19 | 20 | - [Graph Theory](https://github.com/AhmedGamal2212/Competitive-Programming-Sessions/tree/master/Graph%20Theory) 21 | 22 | ## Getting Started 23 | 24 | To get started, clone this repository to your local machine using this command: 25 | 26 | ``` 27 | git clone https://github.com/AhmedGamal2212/Competitive-Programming-Sessions.git 28 | 29 | 30 | ``` 31 | 32 | Then, browse through the topics folders and choose the one that interests you. You can find a list of practice problems and their solutions in each topic folder. 33 | 34 | ## **Materials** 35 | 36 | Each topic is accompanied by a variety of materials, such as lectures, tutorials, and articles. These materials are designed to provide you with a deeper understanding of the concepts and to help you become a better problem solver. 37 | 38 | ## **Practice Problems** 39 | 40 | For each topic, there are practice problems that are designed to help you apply the concepts you've learned. These problems are designed to challenge you and to help you improve your problem-solving skills. 41 | 42 | ## Contributing 43 | 44 | I welcome contributions from the community. If you find a bug, have a suggestion for a new feature or a practice problem, feel free to open an issue or submit a pull request. I appreciate any contributions that can help improve the quality of the content and the overall user experience. -------------------------------------------------------------------------------- /Recursion & Backtracking/README.md: -------------------------------------------------------------------------------- 1 | # Recursion and Backtracking 2 | 3 | Recursion and backtracking are important concepts in competitive programming. They are used to solve problems that can be broken down into smaller subproblems. In this document, we will discuss what recursion and backtracking are, their uses in competitive programming, and provide code snippets to illustrate their implementation. 4 | 5 | ## Recursion 6 | 7 | Recursion is a technique where a function calls itself to solve a problem. It is particularly useful when dealing with problems that can be broken down into smaller subproblems. The function continues to call itself until a base case is reached, at which point the function returns the result. 8 | 9 | ### Example 10 | 11 | ```Python 12 | def factorial(n): 13 | if n == 0: 14 | return 1 15 | else: 16 | return n * factorial(n-1) 17 | 18 | ``` 19 | 20 | In this example, the `factorial` function calls itself with a smaller `n` until `n` reaches 0, at which point the function returns 1. 21 | 22 | ## Backtracking 23 | 24 | Backtracking is a technique used to find all possible solutions to a problem by incrementally building a solution and checking if it satisfies the problem's constraints. If a constraint is not satisfied, the algorithm backtracks and tries a different solution. 25 | 26 | ### Example 27 | 28 | ``` Python 29 | def solve_sudoku(board): 30 | for i in range(9): 31 | for j in range(9): 32 | if board[i][j] == '.': 33 | for k in range(1, 10): 34 | if is_valid(board, i, j, str(k)): 35 | board[i][j] = str(k) 36 | if solve_sudoku(board): 37 | return True 38 | else: 39 | board[i][j] = '.' 40 | return False 41 | return True 42 | 43 | ``` 44 | 45 | In this example, we use backtracking to solve a Sudoku puzzle. The algorithm starts by iterating through the board and finding an empty cell. It then tries each number from 1 to 9 until a valid solution is found. If a solution is not found, the algorithm backtracks and tries a different number. 46 | 47 | Recursion and backtracking are important techniques in competitive programming. They allow us to solve complex problems by breaking them down into smaller subproblems and finding all possible solutions. By understanding these concepts and knowing when to use them, we can write efficient and effective code. 48 | 49 | **And we are here to learn them in practice and get benefit of using them.** 50 | **Enjoy Recursion and Backtracking!** 51 | 52 | ## My Session @ ICPC SCU 53 | 54 | - [Recursion & Backtracking: Part 1](https://www.youtube.com/watch?v=msdBouUEs8w&t=0s&ab_channel=AhmedGamal) 55 | 56 | - [Recursion & Backtracking: Part 2](https://www.youtube.com/watch?v=lBqumRAwEaQ&ab_channel=AhmedGamal) 57 | 58 | 59 | ## Useful Materials 60 | 61 | ### Video Materials 62 | 63 | - [Recursion (Dr.Mostafa Saad)](https://www.youtube.com/watch?v=hyk46UmJPS4&list=PLPt2dINI2MIYmHYBSEdkdKMf_3nzFMveo&ab_channel=ArabicCompetitiveProgramming) 64 | 65 | - [Backtracking (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=hLXVhRzqq18&ab_channel=ArabicCompetitiveProgramming) 66 | 67 | - [Divide & Conquer and Recurrence relations (Videos 18:29)(Abdul Bari)](https://www.youtube.com/playlist?list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O) 68 | 69 | - [Backtracking (Videos 63:67)(Abdul Bari)](https://www.youtube.com/playlist?list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O) 70 | 71 | ### Reading Materials 72 | 73 | - [Introduction to recursion (GeeksforGeeks)](https://www.geeksforgeeks.org/introduction-to-recursion-data-structure-and-algorithm-tutorials/) 74 | 75 | - [Introduction to Backtracking (GeeksforGeeks)](https://www.geeksforgeeks.org/introduction-to-backtracking-data-structure-and-algorithm-tutorials/) 76 | 77 | - [Time complexity of recursion (EnjoyAlgorithms)](https://www.enjoyalgorithms.com/blog/time-complexity-analysis-of-recursion-in-programming) 78 | 79 | ## Practice Problems 80 | 81 | - [Recursion & Backtracking sheets (Assiut's Sheets)](https://codeforces.com/group/gA8A93jony/contests) -------------------------------------------------------------------------------- /Time Complexity/README.md: -------------------------------------------------------------------------------- 1 | # Time Complexity for Competitive Programming 2 | 3 | Welcome to the session "Time Complexity for Competitive Programming" session. This session is designed to help beginner competitive programmers understand the time complexity, which is crucial for writing efficient code. Below, you'll find a brief overview of the key concepts covered in the session. 4 | 5 | ### Key Concepts 6 | 7 | #### 1. Theoretical Side of Code Efficiency 8 | In this section, we discuss why code efficiency is important in competitive programming. Efficient code can mean the difference between solving a problem within the given time limits or facing a time-out error. 9 | 10 | #### 2. Asymptotic Notation 11 | Asymptotic notation provides a way to describe the behavior of functions as they grow towards infinity. It helps in analyzing the efficiency of algorithms, especially when dealing with large inputs. 12 | 13 | #### 3. Big O Notation 14 | Big O notation is used to classify algorithms according to how their run time or space requirements grow as the input size grows. It's a crucial concept for understanding the upper bounds of an algorithm's running time. 15 | 16 | ### Scientific Notation of Numbers 17 | Understanding the scientific notation of numbers is essential for dealing with large numbers frequently encountered in competitive programming. It simplifies the representation and manipulation of these numbers. 18 | 19 | ### Time Complexity Examples 20 | In this section, we solve various examples to illustrate how to calculate the time complexity of different algorithms. These examples help solidify the theoretical concepts discussed and provide practical insights into their application. 21 | 22 | ## My Session @ ICPC SCU 23 | You can watch the recorded session on Time Complexity for Competitive Programming by following [this link to my YouTube Channel](https://youtu.be/XyivAoLPnlg?si=jIvyEUGM4zasXuO1). 24 | 25 | ## Useful Materials 26 | 27 | ### Reading Materials 28 | - [USACO GUIDE's materials for Time Complexity](https://usaco.guide/bronze/time-comp) 29 | 30 | ### Video Materials 31 | - [Time Complexity Analysis by Abdul Bari](https://www.youtube.com/watch?v=xGYsEqe9Vl0&list=PLepRVAscJb6hLEJu77Y9jon8e8S4iUYAg) 32 | - [Learn Big O Notation in 6 minutes by Bro Code](https://youtu.be/XMUe3zFhM5c?si=M6Qhqj2t1UMpBE5H) -------------------------------------------------------------------------------- /Two Pointers/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Two Pointers and Sliding Window Techniques 3 | 4 | ## Two Pointers 5 | 6 | Two pointers is a technique that is often used in competitive programming to solve problems that involve iterating over two or more points in an array or a sequence. The basic idea behind this technique is to use two pointers, one at the start and another at the end of the sequence, and move them towards each other until they meet. 7 | 8 | One common problem that can be solved using the two pointers technique is finding a pair of integers in an array that add up to a given target value. To solve this problem, we can first sort the array and then use two pointers to scan the array from both ends. If the sum of the two elements pointed by the two pointers is less than the target value, we move the left pointer to the right. If the sum is greater than the target value, we move the right pointer to the left. If the sum is equal to the target value, we have found a pair of integers that add up to the target value. 9 | 10 | ## Sliding Window 11 | 12 | Sliding window is another technique that is often used in competitive programming to solve problems that involve finding a subarray or a substring that satisfies certain conditions. The basic idea behind this technique is to use a window that slides over the sequence, and update the window as we go. 13 | 14 | One common problem that can be solved using the sliding window technique is finding the maximum sum of a subarray of size k in an array. To solve this problem, we can first compute the sum of the first k elements of the array. Then we slide the window by one element at a time and update the sum by subtracting the first element of the window and adding the next element of the array. We keep track of the maximum sum we have seen so far, and return it as the answer. 15 | 16 | These two techniques are very useful in competitive programming, and can be used to solve a wide range of problems efficiently. By mastering these techniques, you can become a more confident and skilled programmer. 17 | 18 | **And we are here to learn them in practice and get benefit of using them.** 19 | **Enjoy Two Pointers and Sliding Window!** 20 | 21 | ## My Session @ ICPC SCU 22 | 23 | - [Two Pointers Technique](https://youtu.be/uplty7GJ9qg) 24 | 25 | ## Useful Materials 26 | 27 | > I highly recommend starting with **CodeForces EDU** section 28 | 29 | - [Two Pointers (CodeForces EDU)](https://codeforces.com/edu/course/2/lesson/9) 30 | 31 | ### Reading Materials 32 | 33 | - [Two Pointers Technique (Geeks for Geeks)](https://www.geeksforgeeks.org/two-pointers-technique/) 34 | 35 | - [Sliding Window Technique (Geeks for Geeks)](https://www.geeksforgeeks.org/window-sliding-technique/) 36 | 37 | ### Video Materials 38 | 39 | - [Two Pointers Technique (Dr. Mostafa Saad)](https://www.youtube.com/watch?v=n-Xwrr8RFQ0&list=PLPt2dINI2MIZeC3RhQ-edPLuwtS9NRZ80&index=2) 40 | 41 | - [Virtual Introduction to Two Pointers](https://www.youtube.com/watch?v=On03HWe2tZM) 42 | 43 | - [Two Pointers in Coding Interviews Stream (Errichto)](https://www.youtube.com/watch?v=QwN-weNSrAg) 44 | 45 | ## Practice Problems 46 | 47 | - [Two Pointers Sheet (ICPC SCU)](https://codeforces.com/group/KQlzWufN6x/contests) 48 | --------------------------------------------------------------------------------