├── .vscode └── settings.json ├── Our Curriculum └── NET Developer (6).png ├── Practice-Session#1 ├── F-Expired .cpp ├── H-Sharing_Cookies copy.cpp ├── I-K-City.cpp ├── K-Meal-Delivery .cpp └── app ├── README.md ├── Session#1 ├── Session#1.pptx ├── app ├── app.cpp └── app.py ├── Session#2 ├── Session#2.pptx ├── app └── app.cpp ├── Session#3 ├── Session#3.pptx ├── app ├── app.cpp ├── app2 └── app2.cpp ├── Session#4 ├── Session#4.pptx ├── app └── app.cpp ├── Session#5 - TimeComplexity ├── Session#5.pdf ├── app ├── app.cpp ├── app2 ├── app2.cpp ├── lib-funcs └── lib-funcs.cpp ├── Session#5 ├── Session#5.pdf ├── palandrom-number.cpp ├── palandrom-number.exe ├── rining.cpp ├── substrings.cpp └── substrings.exe ├── Session#6.2 ├── Session#6.pdf ├── app └── app.cpp ├── Session#6 ├── Session#6.pdf ├── main ├── main.cpp ├── main2 ├── main2.cpp └── meetingAttendanceList.csv ├── Session#7 ├── app ├── app.cpp ├── app2 ├── app2.cpp ├── main ├── main.cpp └── output.txt ├── Session#8 ├── linked-list └── linked-list.cpp └── Session#Stack └── Stack.cpp /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.ejs": "html", 4 | "iostream": "cpp", 5 | "ostream": "cpp", 6 | "iomanip": "cpp", 7 | "random": "cpp", 8 | "cmath": "cpp", 9 | "numeric": "cpp", 10 | "*.tcc": "cpp", 11 | "string": "cpp", 12 | "string_view": "cpp", 13 | "istream": "cpp", 14 | "sstream": "cpp", 15 | "stdexcept": "cpp", 16 | "system_error": "cpp", 17 | "typeinfo": "cpp", 18 | "array": "cpp", 19 | "atomic": "cpp", 20 | "bit": "cpp", 21 | "cctype": "cpp", 22 | "clocale": "cpp", 23 | "compare": "cpp", 24 | "concepts": "cpp", 25 | "cstdarg": "cpp", 26 | "cstddef": "cpp", 27 | "cstdint": "cpp", 28 | "cstdio": "cpp", 29 | "cstdlib": "cpp", 30 | "ctime": "cpp", 31 | "cwchar": "cpp", 32 | "cwctype": "cpp", 33 | "deque": "cpp", 34 | "unordered_map": "cpp", 35 | "vector": "cpp", 36 | "exception": "cpp", 37 | "algorithm": "cpp", 38 | "functional": "cpp", 39 | "iterator": "cpp", 40 | "memory": "cpp", 41 | "memory_resource": "cpp", 42 | "tuple": "cpp", 43 | "type_traits": "cpp", 44 | "utility": "cpp", 45 | "initializer_list": "cpp", 46 | "iosfwd": "cpp", 47 | "limits": "cpp", 48 | "new": "cpp", 49 | "numbers": "cpp", 50 | "streambuf": "cpp" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Our Curriculum/NET Developer (6).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Our Curriculum/NET Developer (6).png -------------------------------------------------------------------------------- /Practice-Session#1/F-Expired .cpp: -------------------------------------------------------------------------------- 1 | /* 2 | H,I 3 | F 4 | 5 | 6 | */ 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | /* 15 | He bays A days before X 16 | 17 | he by at time (X - A) => Date 18 | 19 | ate it at time => A+B 20 | 21 | 4 3 6 22 | X A B 23 | 24 | X-A = 4-3 = 1 25 | A+B = 3+6 = 9 26 | 27 | 28 | 6 5 1 29 | X A B 30 | => 31 | by at => 6-5 = 1 => Date 32 | ate at => 1 + 1 => 2 33 | 34 | when is it delicious? BuyDate <= AteAt <= X+1 35 | 1 <= 2 <= 7 36 | 37 | 38 | 3 7 12 39 | X A B 40 | 41 | buyDate = 3-7 = -4 42 | ateAt = -4 + 12 = 8 43 | 44 | BuyDate <= AteAt <= X+1 45 | 46 | -4 <= 8 <= 4 => false => dangerous 47 | 48 | */ 49 | 50 | long long X, A, B; 51 | cin >> X >> A >> B; 52 | // current time 0 53 | // bought at time -A => 5 => a = 3 , 2 54 | // at at time -A+B => 2+6 = 8 55 | // X => delicious 56 | // X+1 => safe 57 | // X+1 > AteAt => dangerous 58 | 59 | long long BuyDate = -A; 60 | long long AteAt = BuyDate + B; 61 | 62 | if (BuyDate <= AteAt && AteAt < X - A) 63 | { 64 | cout << "delicious" << endl; 65 | } 66 | else if (BuyDate <= AteAt && AteAt < X + 1) 67 | { 68 | cout << "safe" << endl; 69 | } 70 | else 71 | { 72 | cout << "dangerous" << endl; 73 | } 74 | } -------------------------------------------------------------------------------- /Practice-Session#1/H-Sharing_Cookies copy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | */ 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | /* 12 | 13 | */ 14 | 15 | long long n, m; 16 | 17 | cin >> n >> m; 18 | cout << (n - 1) * (m - 1) << endl; 19 | } -------------------------------------------------------------------------------- /Practice-Session#1/I-K-City.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | H,I 3 | F 4 | 5 | 6 | */ 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | /* 15 | he has A,B packets of cookies 16 | he has three goats 17 | he can use A only 18 | or B only 19 | or both 20 | 21 | he wants to give each goat the same number of cookies 22 | 23 | A=> divide by 3 24 | B=> divide by 3 25 | A+b => divide by 3 26 | */ 27 | 28 | long long A, B; 29 | cin >> A >> B; 30 | if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) 31 | { 32 | cout << "Possible" << endl; 33 | } 34 | else 35 | { 36 | cout << "Impossible" << endl; 37 | } 38 | } -------------------------------------------------------------------------------- /Practice-Session#1/K-Meal-Delivery .cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | */ 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | /* 12 | 13 | */ 14 | 15 | int X, a, b; 16 | cin >> X >> a >> b; 17 | 18 | if (abs(X - a) < abs(X - b)) 19 | { 20 | cout << "A" << endl; 21 | } 22 | else 23 | { 24 | cout << "B" << endl; 25 | } 26 | } -------------------------------------------------------------------------------- /Practice-Session#1/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Practice-Session#1/app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Problem Solving Course

2 | 3 | 4 |

Intro Session

5 | > https://drive.google.com/file/d/1CT3t1YsXwGpisMp9If8xWWmfkOS0CLbv/view?usp=sharing 6 |
Presentation
7 | > https://prezi.com/view/qDFLoGfa1GaDeQO7hoPP/ 8 | 9 | 10 |

Session 1:

11 | https://drive.google.com/file/d/1bXmf0i93Ql412jPOLsGFyPgMhRp0c_dz/view?usp=drivesdk 12 |

Session 2:

13 | https://drive.google.com/file/d/1UHDCVgguLXTr1hzjp0bZW3hUHpoitYh8/view?usp=drivesdk 14 |

Session 3:

15 | https://drive.google.com/file/d/1iBoKbZuyXCK5Xtl_WNhyIx-NgSru5WPK/view?usp=drivesdk 16 |

Session 4:

17 | https://drive.google.com/file/d/1K--zCi0yuXkpokimbSiEQltBHU_BNnCx/view?usp=drivesdk 18 |

Session 5:

19 | 20 | - part 1: https://drive.google.com/file/d/1m27ZVb4o0o3xtfQb0SPy00bDMZ_FfVCJ/view?usp=drivesdk 21 | 22 | - part 2: https://drive.google.com/file/d/1hKzj3tr5xEXCBdwVTaHEasn8ahqmI-ko/view?usp=drivesdk 23 | 24 |

Session 6: Pointers

25 | 26 | - part 1: https://drive.google.com/file/d/1_lz1IxzwhNtulKdQF-Xpy78Wr1np-0Up/view?usp=drive_link 27 | 28 | - part 2: https://drive.google.com/file/d/1aQyE5DFcVtKdECnWXpkQsDBiW1bwbdqB/view?usp=drive_link 29 | 30 |

Session 7: Basic OOP:

31 | 32 |

Session 8: Linked List

33 | https://drive.google.com/file/d/15pDqKAwacJ8vMKrJtwo7JOGZwYAsLB-8/view?usp=drive_link 34 | 35 |

Session 9: Stack and Queue

36 | 37 | - part 1: https://drive.google.com/file/d/1GLMKik9ERgBbUSb9IEPV3dVvS68W0e1l/view?usp=drive_link 38 | 39 | - part 2: https://drive.google.com/file/d/1Ok75DYxnekkptZN5pysU72dyluH3W4AA/view?usp=drive_lin 40 | 41 |

Session 10: Miscellaneous

42 | https://drive.google.com/file/d/1i9kqAIKYviit2ejFPAP0enR_IA3fswWu/view?usp=drive_link 43 | -------------------------------------------------------------------------------- /Session#1/Session#1.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#1/Session#1.pptx -------------------------------------------------------------------------------- /Session#1/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#1/app -------------------------------------------------------------------------------- /Session#1/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // int a = 10; // take values from -2000000000 to 2000000000 9 | // long long b = 23; // take values from -9000000000000000000 to 9000000000000000000 10 | // char c = 'A'; 11 | // char d = 65; // takes values from -128 to 127 12 | // string e = "Hello"; 13 | // // unsigned when put before the data type, it will only take positive values 14 | // unsigned int x = 10; // 0 -> 18 * 1000000000000000000 15 | // long double aa = 10.0; // 100 *1000000000000000000 not recommended, very very slow 16 | 17 | // a = 20 + 10; 18 | 19 | // aa = x + a; 20 | // int X = 99; 21 | // int remidner = X % 2; // 1 22 | 23 | // string name = "Ali"; 24 | // string lastName = "Khan"; 25 | // string fullName = name + " " + lastName; 26 | 27 | // a += 10; // a = a + 10; 28 | // a -= 10; // a = a - 10; 29 | // a *= 10; // a = a * 10; 30 | // a /= 10; // a = a / 10; 31 | // a %= 5; // a = a % 5; 32 | // name += " " + lastName; // name = name + " " + lastName; 33 | 34 | // cout << name << endl; 35 | 36 | /// read input from file, user, console => standered input stream 37 | 38 | // string x; 39 | 40 | // getline(cin, x); // reads a whole line 41 | 42 | // cout << "The value of x is: " << x << endl; 43 | 44 | // int a; 45 | // cin >> a; 46 | // cout << "The value of a is: " << a << endl; 47 | 48 | // double somedouble; 49 | // cin >> somedouble; 50 | // cout << fixed << setprecision(2) << somedouble << endl; 51 | 52 | /* 53 | simple programe to 54 | 1. take two numbers from the user 55 | 2. add them 56 | 3. print the result 57 | 58 | this is a commented part 59 | */ 60 | 61 | // int a, b; 62 | // cout << "Enter the first number: "; 63 | // cin >> a; 64 | // cout << "Enter the second number: "; 65 | // cin >> b; 66 | 67 | // int result = a + b; 68 | // cout << "The result is: " << result << endl; 69 | 70 | // int a, b; 71 | // cout << "Enter the two numbers: "; 72 | // cin >> a >> b; 73 | 74 | // int result = a + b; 75 | // cout << "The result is: " << result << endl; 76 | 77 | return 0; 78 | } -------------------------------------------------------------------------------- /Session#1/app.py: -------------------------------------------------------------------------------- 1 | print("Hello world!") 2 | print("Hello world!") 3 | print("Hello world!") 4 | print("Hello world!") 5 | print("Hello world!") 6 | print("Hello world!") 7 | print("Hello world!") 8 | print("Hello world!") 9 | 10 | 11 | -------------------------------------------------------------------------------- /Session#2/Session#2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#2/Session#2.pptx -------------------------------------------------------------------------------- /Session#2/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#2/app -------------------------------------------------------------------------------- /Session#2/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | /* 8 | what is if statement? 9 | 10 | 11 | boolen => true or false 12 | 13 | true => any number other than 0 14 | false => 0 15 | 16 | if( boolean experssion) 17 | { 18 | // code 19 | } 20 | 21 | if( some condtion) { 22 | 23 | if (another condition) { 24 | if (another condition) { 25 | 26 | } else { 27 | 28 | } 29 | } else if() 30 | 31 | } else if() 32 | */ 33 | 34 | // int Age; 35 | // cin >> Age; 36 | 37 | // if (Age >= 18) 38 | // { 39 | // cout << "Age is greater than 18" << endl; 40 | 41 | // if (Age >= 100) 42 | // { 43 | // cout << "Age is greater than 100" << endl; 44 | // } 45 | // else 46 | // { 47 | // cout << "Age is less than 100" << endl; 48 | // } 49 | // } 50 | // else 51 | // { 52 | // cout << "Age is less than 18" << endl; 53 | // } 54 | 55 | // if (Age >= 18 and Age >= 100) 56 | // { 57 | // cout << "Age is greater than 18" << endl; 58 | // cout << "Age is greater than 100" << endl; 59 | // } 60 | // // else if (Age >= 18 and Age < 100) 61 | // // { 62 | 63 | // // cout << "Age is greater than 18" << endl; 64 | // // } 65 | // // else 66 | // // { 67 | // // cout << "Age is less than 18" << endl; 68 | // // } 69 | 70 | // switch (Age) 71 | 72 | // int Age; 73 | 74 | // cin >> Age; 75 | 76 | // switch (Age) 77 | // { 78 | // case 18: 79 | // cout << "Age is 18" << endl; 80 | // // break; 81 | // case 20: 82 | // cout << "Age is 20" << endl; 83 | // // break; 84 | 85 | // default: 86 | // cout << "Age is not 18 or 20" << endl; 87 | // // break; 88 | // } 89 | 90 | // Loop => means to repeat something 91 | // For Loop , while loop, do while loop 92 | // int counter = 1; 93 | // while (counter) // 1 < 10 => true, 2 < 10? true , 3 < 10? true, 10 <= 10? true , 11 <= 10? false 94 | // { 95 | // // code while run while the expression is true 96 | // // cout << "The value of counter is: " << counter << endl; 97 | // // counter++; 98 | 99 | // // if() , 100 | 101 | // int value = 43; 102 | // value += counter; 103 | 104 | // cout << "The value of value is: " << value << endl; 105 | // } 106 | // // when infinite loop hapeens? when the condition is always true 107 | // cout << "Code after loop" << endl; 108 | 109 | // bool isExit = 0; // fa;se 110 | // while (not isExit) // not exit not false => true , isExtit = 1, true, not true => false 111 | // { 112 | // int Age; 113 | // cout << "Enter your age: "; 114 | // cin >> Age; 115 | 116 | // if (Age >= 18) 117 | // { 118 | // cout << "You are an adult" << endl; 119 | // } 120 | // else 121 | // { 122 | // cout << "You are to young" << endl; 123 | // } 124 | 125 | // char choice; 126 | // cout << "Do you want to exit? (y/n): "; 127 | // cin >> choice; 128 | 129 | // if (choice == 'y') 130 | // { 131 | // isExit = 1; 132 | // } 133 | // } 134 | 135 | // for loop 136 | // for (variale initlztion; condition; update) 137 | 138 | // for (int i = 1; i <= 10; i++) 139 | // { 140 | // int value; 141 | // cout << "Enter a number: "; 142 | // cin >> value; 143 | 144 | // cout << value * 2 << endl; 145 | // } 146 | 147 | // bool isExit = 0; 148 | // while (not isExit) 149 | // { 150 | // int numberOfIterations; 151 | 152 | // cout << "Enter the number of iterations: "; 153 | // cin >> numberOfIterations; 154 | 155 | // for (int i = 0; i < numberOfIterations; i++) 156 | // { 157 | // int value; 158 | // cout << "Enter a number: "; 159 | // cin >> value; 160 | 161 | // cout << value * 2 << endl; 162 | // } 163 | 164 | // cout << "Do you want to exit? (1/0): "; 165 | // cin >> isExit; 166 | // } 167 | 168 | // for (int i = 0; i < 10; i++) 169 | // { 170 | // // another loop 171 | // for (int j = 0; j < 10; j++) 172 | // { 173 | // cout << "i: " << i << " j: " << j << endl; 174 | // // cout << "i+j: " << i + j << endl; 175 | // } 176 | // } 177 | 178 | // do while loop => while loop => works atleast once 179 | 180 | // bool condtion = 0; 181 | // do 182 | // { 183 | // cout << "This will run atleast once" << endl; 184 | // } while (condtion); 185 | 186 | /* 187 | 1. user will enter a number 188 | 2. print the sum of numbers from 1 to the number 189 | 190 | user enters 10 191 | 192 | sum = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 193 | 194 | print sum 195 | */ 196 | 197 | // int number; 198 | // cout << "Enter a number: "; 199 | // cin >> number; 200 | 201 | // cout << (number + 1) * number / 2 << endl; 202 | // // sum of numbers from 1 to that number , 1 + 2 + 3 + 4 ............ number 203 | // // 1+2+3+4+5 => 15 204 | // // int sum = 0; 205 | 206 | // // for (int i = 0; i <= number; i++) 207 | // // { 208 | // // sum += i; 209 | // // } 210 | 211 | // cout << sum << endl; 212 | 213 | // break and continue key words in c++ and all programming languages 214 | 215 | // for (int i = 1; i <= 10; i++) 216 | // { 217 | // if (i == 5) 218 | // { 219 | // // break; 220 | // continue; 221 | // cout << "This will not run" << endl; 222 | // } 223 | // cout << "This will not work for i = 5" << endl; 224 | // cout << i << endl; 225 | // } 226 | 227 | // cout << "Code after loop" << endl; 228 | 229 | return 0; 230 | } -------------------------------------------------------------------------------- /Session#3/Session#3.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#3/Session#3.pptx -------------------------------------------------------------------------------- /Session#3/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#3/app -------------------------------------------------------------------------------- /Session#3/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // return type, function name, parameters 6 | // function body 7 | // int, double, float , string, char, bool 8 | 9 | // void rectangleArea(int a, int b) 10 | // { 11 | // // some calculations 12 | 13 | // a *= 2; 14 | // b *= 4; 15 | 16 | // cout << "Area: " << a * b << endl; 17 | 18 | // // return; 19 | // } 20 | // double circleArea(double raduis) 21 | // { 22 | // return 3.14 * raduis * raduis; 23 | // } 24 | 25 | // double circleArea(double raduis) 26 | // { 27 | // return 3.14 * raduis * raduis; 28 | // } 29 | 30 | // double areaOfRectangle(double width, double height) 31 | // { 32 | // } 33 | 34 | // double areaOfcircle(double radius) 35 | // { 36 | // } 37 | // double areaOfTriangle(double a, double b, double c) 38 | // { 39 | // } 40 | 41 | //!!!!!!!! cannot overload function based on return type 42 | 43 | // double area(double width, double height) 44 | // { 45 | // return width * height; 46 | // } 47 | 48 | // double area(double radius) 49 | // { 50 | // return 3.14 * radius * radius; 51 | // } 52 | // double area(double a, double b, double c) 53 | // { 54 | // double s = (a + b + c) / 2; 55 | // return sqrt(s * (s - a) * (s - b) * (s - c)); 56 | // } 57 | 58 | // int add(int a, int b) 59 | // { 60 | // cout << "called int" << endl; 61 | // return a + b; 62 | // } 63 | 64 | // double add(double a, double b) 65 | // { 66 | // cout << "called double" << endl; 67 | // return a + b; 68 | // } 69 | // string add(string a, string b) 70 | // { 71 | // cout << "called string" << endl; 72 | // return a + b; 73 | // } 74 | 75 | // string add(string a, int b) 76 | // { 77 | // cout << "called string int" << endl; 78 | // return a + to_string(b); 79 | // } 80 | // int add(int a, string b) 81 | // { 82 | // cout << "called int string" << endl; 83 | // return a + stoi(b); // string to int 84 | // } 85 | 86 | // int add(int, int); 87 | // int multiply(int, int); 88 | 89 | // int add(int a, int b) 90 | // { 91 | // int c = multiply(a, b); 92 | // return a + b + c; 93 | // } 94 | 95 | // int multiply(int a, int b) 96 | // { 97 | // return a * b; 98 | // } 99 | 100 | int main() 101 | { 102 | 103 | // cout << "1. Area of Rectangle" << endl; 104 | // cout << "2. Area of Circle" << endl; 105 | // cout << "3. Area of Triangle" << endl; 106 | 107 | // int choice; 108 | // cout << "Enter your choice: "; 109 | // cin >> choice; 110 | // if (choice == 1) 111 | // { 112 | // double width, height; 113 | // cout << "Enter width: "; 114 | // cin >> width; 115 | // cout << "Enter height: "; 116 | // cin >> height; 117 | // cout << "Area: " << area(width, height) << endl; 118 | // } 119 | // else if (choice == 2) 120 | // { 121 | // double radius; 122 | // cout << "Enter radius: "; 123 | // cin >> radius; 124 | // cout << "Area: " << area(radius) << endl; 125 | // } 126 | // else if (choice == 3) 127 | // { 128 | // double a, b, c; 129 | // cout << "Enter a: "; 130 | // cin >> a; 131 | // cout << "Enter b: "; 132 | // cin >> b; 133 | // cout << "Enter c: "; 134 | // cin >> c; 135 | // cout << "Area: " << area(a, b, c) << endl; 136 | // } 137 | // else 138 | // { 139 | // cout << "Invalid choice" << endl; 140 | // } 141 | 142 | // cout << add(2, 3) << endl; 143 | // cout << add(2.5, 3.5) << endl; 144 | // cout << add("Hello", "World") << endl; 145 | // cout << add("Hello", 5) << endl; 146 | // cout << add(5, "5") << endl; 147 | 148 | // int a = 100; 149 | 150 | // if (1) 151 | // { 152 | // // scope 153 | // int a = 1; // not the same a as above 154 | // cout << "INSID IF: " << a << endl; 155 | // } 156 | // cout << "INSIE MAIN: " << a << endl; 157 | // int i = 1; 158 | // while (i) 159 | // { 160 | // // scope 161 | // a = 10; 162 | 163 | // cout << "INSID WHILE: " << a << endl; 164 | 165 | // i--; 166 | // } 167 | 168 | // int f = add(2, 3); 169 | // cout << "c" << " " << c << endl; 170 | // cout << f << endl; 171 | 172 | // cout << "INSIE MAIN: " << a << endl; 173 | 174 | // int a = 10, b = 20; 175 | // cout << add(a, b) << endl; 176 | 177 | return 0; 178 | } 179 | 180 | // double circleArea(double raduis) 181 | // { 182 | // return 3.14 * raduis * raduis; 183 | // } 184 | -------------------------------------------------------------------------------- /Session#3/app2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#3/app2 -------------------------------------------------------------------------------- /Session#3/app2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // const double PI = 3.14; 6 | 7 | // double circleArea(double raduis) 8 | // { 9 | // return PI * raduis * raduis; 10 | // } 11 | 12 | // void someFunction() 13 | // { 14 | // PI = 5; 15 | // } 16 | // pass by value -> copy of the value 17 | // pass by reference -> reference to the value 18 | 19 | // void change(int &b) 20 | // { 21 | // b = 100; // alters the value of x 22 | // } 23 | int main() 24 | { 25 | // int x = 5; 26 | // change(x); 27 | // cout << x << endl; 28 | // someFunction(); 29 | // cout << circleArea(1) << endl; 30 | 31 | // lamda function is a function can be assigned to a variable 32 | // const double PI = 3.14; 33 | 34 | // auto circleArea = [&](double raduis) -> double 35 | // { 36 | // return PI * raduis * raduis; 37 | // }; 38 | 39 | /* 40 | 41 | function name = [&](parameter1,parameter2) -> returnType 42 | { 43 | // function body 44 | // return 45 | }; 46 | 47 | */ 48 | // x is a normal variable 49 | // Type name value 50 | // function x = [&](int a, int b) -> int 51 | // { 52 | // return a + b; 53 | // }; 54 | 55 | // cout << x(5, 6) << endl; 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Session#4/Session#4.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#4/Session#4.pptx -------------------------------------------------------------------------------- /Session#4/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#4/app -------------------------------------------------------------------------------- /Session#4/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | // void pass_array(int *arr, int n) // array pass by reference 8 | // { 9 | // for (int i = 0; i < n; i++) 10 | // { 11 | // cout << arr[i] << " "; 12 | // } 13 | // } 14 | // void pass_vec 15 | 16 | // void pass_vector(vector &v) 17 | // { 18 | // for (int i = 0; i < v.size(); i++) 19 | // { 20 | // cout << v[i] << " "; 21 | // } 22 | // } 23 | // void pass_string(string &str) 24 | // { 25 | // } 26 | // void pass_int(int &x) 27 | // { 28 | // } 29 | 30 | int my_compare(string &str1, string &str2) 31 | { 32 | int answer = 0; 33 | for (int i = 0; i < str1.size(); i++) 34 | { 35 | if (i > str2.size()) 36 | return answer; 37 | 38 | answer += str1[i] - str2[i]; 39 | } 40 | 41 | return answer; 42 | } 43 | int main() 44 | { 45 | // string str = "Bbcdedfghij"; 46 | // string str2 = "AbcdedfghiK"; 47 | // cout << str2.compare(str) << endl; first index where the strings differ 48 | // cout << my_compare(str, str2) << endl; 49 | // int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 50 | // pass_array(arr, 10); 51 | 52 | // int n = 40; 53 | // vector v(10, 0); 54 | // pass_vector(v); 55 | // int arr[n] = {}; 56 | 57 | // arr[0] = 10; 58 | // arr[1] = 20; 59 | // arr[6] = 30; 60 | // for (int i = 0; i < n; i++) 61 | // { 62 | // cout << arr[i] << " "; 63 | // } 64 | // cout << endl; 65 | 66 | // int n; 67 | 68 | // cout << "Enter the size of the array: "; 69 | // cin >> n; 70 | // int arr[n + 1]; // 0 1 2 3 4 5 6 ........ n-1 71 | // // arr[n] => out of bound 72 | // for (int i = 1; i <= n; i++) 73 | // { 74 | // cout << "Enter the value of arr[" << i << "]: "; 75 | // cin >> arr[i]; 76 | // } 77 | 78 | // for (int i = 1; i <= n; i++) 79 | // { 80 | // cout << "arr[" << i << "]: " << arr[i] << endl; 81 | // } 82 | 83 | /* 84 | what is a string? 85 | 86 | string is an array of characters 87 | */ 88 | 89 | // char str[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', '\0'}; 90 | 91 | // int x = 'a' + 'x'; // => 92 | // cout << x << endl; 93 | // str[0] = 'z'; 94 | 95 | // string str = "abcdedfghij"; // jihgfedcba 96 | // str.append("!!!"); 97 | // reverse(str.begin() + 3, str.end() - 5); 98 | // str.erase(3, 4); 99 | // string co = str.substr(3, str.size() - 3); 100 | // cout << co << endl; 101 | // cout << str << endl; 102 | // cout << str << endl; 103 | // cout << str.at(-1) << endl; 104 | // str[0] = 'x'; 105 | // cout << str << endl; 106 | // string somestring = "some string"; 107 | // string searchSrting = "stringgg"; 108 | // if (somestring.find(searchSrting) != -1) 109 | // { 110 | // cout << "Found" << endl; 111 | // return 0; 112 | // } 113 | // else 114 | // cout << "Not Found" << endl; 115 | 116 | // vector is a dynamic array 117 | 118 | // vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 119 | // v[0] = 1; 120 | 121 | // v.pop_back(); // remove 122 | // for (int i = 0; i < v.size(); i++) 123 | // { 124 | // cout << v[i] << " "; 125 | // } 126 | // cout << endl; 127 | 128 | // vector v(5, "I am a string"); 129 | 130 | // v.at(5) = "I"; 131 | // v[5] = "I"; 132 | // v.pop_back(); 133 | // for (int i = 0; i < v.size(); i++) 134 | // { 135 | // cout << v[i] << endl; 136 | // } 137 | 138 | // vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 139 | 140 | // v[4] = 30000; 141 | 142 | // for (int i = 0; i < v.size(); i++) 143 | // { 144 | // cout << v[i] << " "; 145 | // } 146 | // cout << endl; 147 | 148 | // v = vector(5, 5); 149 | 150 | // for (int i = 0; i < v.size(); i++) 151 | // { 152 | // cout << v[i] << " "; 153 | // } 154 | 155 | // cout << endl; 156 | 157 | // vector v2 = {1}; 158 | // v += v2; 159 | 160 | // bool isPresent = find(v.begin(), v.end(), 10); 161 | 162 | // for each loop 163 | 164 | // int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 165 | // for (int &x : arr) 166 | // { 167 | // // x = 100; 168 | // cout << x << " "; 169 | // } 170 | // cout << endl; 171 | 172 | // for (int i = 0; i < v.size(); i++) 173 | // { 174 | // cout << v[i] << " "; 175 | // } 176 | // cout << endl; 177 | 178 | // int n; 179 | // cin >> n; 180 | // vector v, x; 181 | // v = x = vector(n, 0); 182 | 183 | // for (int i = 0; i < n; i++) 184 | // { 185 | // cin >> v[i]; 186 | // } 187 | // for (int i = 0; i < n; i++) 188 | // cin >> x[i]; 189 | // for (int i = 0; i < n; i++) 190 | // { 191 | // cout << v[i] << " "; 192 | // } 193 | // cout << endl; 194 | // for (int i = 0; i < n; i++) 195 | // { 196 | // cout << x[i] << " "; 197 | // } 198 | // cout << endl; 199 | // a b c d e f g h i j k 200 | } -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/Session#5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5 - TimeComplexity/Session#5.pdf -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5 - TimeComplexity/app -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | /* 8 | Time Complexity => means how much time it takes to run the code 9 | 10 | time Complexity => depends on the number of lines of code 11 | */ 12 | // const int n = 10; 13 | // // cin >> n; 14 | // for (int i = 0; i < n; i++) // n times 15 | // { 16 | // cout << i << endl; 17 | // } 18 | // complexity => O(1) => constant time 19 | // time complexity => O(n) 20 | // itraions => times 21 | // O(itraions) => maximum number of steps to run the code 22 | // O(N) => N times variable 23 | 24 | // int n; // O(1) 25 | // cin >> n; // O(1) 26 | // int arr[n]; // O(1) 27 | 28 | // for (int i = 0; i < n; i++) // n times => O(n) 29 | // { 30 | // cin >> arr[i]; 31 | // } 32 | // for (int i = 0; i < n; i++) // n times => O(n) 33 | // { 34 | // cout << arr[i] << " "; 35 | // } 36 | // O(1) + O(1) + O(1) + O(n) + O(n) 37 | // O(3) + O(2n) 38 | // O(3 + 2n) 39 | // O(2n) 40 | // O(n) 41 | // caculate for each element the number of elements smaller than it 42 | 43 | // for (int i = 0; i < n; i++) // n times => O(n) 44 | // { 45 | // int count = 0; // O(1) 46 | // for (int j = 0; j < n; j++) // n times => O(n) 47 | // { 48 | // if (arr[j] < arr[i]) // O(1) 49 | // { 50 | // count++; // O(1) 51 | // } 52 | // } 53 | // cout << count << " "; // O(1) 54 | // } 55 | // cout << endl; 56 | 57 | /* 58 | O(n) + O(n) + O(n*n) + O(n) 59 | O(3n + n^2) 60 | O(n^2) 61 | */ 62 | 63 | /* 64 | which one is better => O(n) or O(n^2) 65 | */ 66 | 67 | // int n, m; 68 | // cin >> n >> m; 69 | // int arr[n]; 70 | // int arr2[m]; 71 | 72 | // for (int i = 0; i < n; i++) // n times => O(n) 73 | // { 74 | // cin >> arr[i]; 75 | // } 76 | // for (int i = 0; i < m; i++) // m times => O(m) 77 | // { 78 | // cin >> arr2[i]; 79 | // } 80 | 81 | // for (int i = 0; i < n; i++) // n times => O(n) 82 | // { 83 | // int counter = 0; // O(1) 84 | // for (int j = 0; j < m; j++) // m times => O(m) 85 | // { 86 | // if (arr[i] > arr2[j]) // O(1) 87 | // { 88 | // counter++; // O(1) 89 | // } 90 | // } 91 | 92 | // cout << counter << " "; // O(1) 93 | // } 94 | 95 | /* 96 | O(n) + O(m) + O(n) + O(n*m) + O(n*m) + O(n*m) + O(n) 97 | 98 | O(3n + m + 3*n*m) 99 | 100 | O(n + m + n*m) 101 | 102 | O(n*m) => n*m != n*n 103 | */ 104 | 105 | // int n, m, k; 106 | // cin >> n >> m >> k; 107 | // int arr[k]; 108 | // int matrix[n][m]; // array of arrays => matrix 109 | /* 110 | 0 1 2 111 | 1 2 3 => 0 112 | 4 5 6 => 1 113 | 7 8 9 => 2 114 | 115 | 1 => arr[0][0] 116 | 9 => arr[2][2] 117 | 7 => arr[2][0] 118 | */ 119 | // for (int i = 0; i < n; i++) 120 | // { 121 | // for (int j = 0; j < m; j++) 122 | // { 123 | // cin >> matrix[i][j]; 124 | // } 125 | // } 126 | 127 | // for (int i = 0; i < k; i++) 128 | // { 129 | // cin >> arr[i]; 130 | // } 131 | 132 | // for (int i = 0; i < k; i++) 133 | // { 134 | // for (int i = 0; i < k; i++) 135 | // { 136 | // } 137 | // } // O(k*k) => O(k^2) 138 | 139 | /* 140 | O(n*m) + O(k^2) 141 | => assume k > n*m 142 | => worst case is n*m is worng 143 | O(n*m + k^2) 144 | 145 | why we did not remove k? 146 | k is the largest power for this variable 147 | 148 | when to remove ? 149 | n , m , n*m 150 | 151 | n n*m? n > n*m => impossible remove n 152 | m n*m? m > n*m => impossible remove m 153 | k n*m? k > n*m => possible must add k 154 | k k^2? k > k^2 => impossible => remove k 155 | 156 | // in the case n and m not zero 157 | */ 158 | 159 | // calculate the speed of the code 160 | 161 | /* 162 | codeforces, hackerrank, leetcode, topcoder, atcoder 163 | 1s => 10^9 operations 164 | 2s => 2*10^9 operations 165 | 10s => 10^10 operations 166 | */ 167 | 168 | int n; 169 | // cin >> n; 170 | // long long X = 1378; 171 | // // X^n X*X*X........ X*X*X => n times 172 | // // last digit of a number => number % 10 173 | // long long res = 1; 174 | // for (int i = 0; i < n; i++) // 2 operations inside the loop 175 | // { 176 | // res *= X; // 1 operation 177 | // res %= 10; // 1 operation 178 | // } 179 | // /* 180 | // Time Complexity => O(n) 181 | // n upper bound is 10^9 182 | 183 | // 10^9 * (2+1+log10(res)) => 12 * 10^9 184 | // */ 185 | 186 | // cout << res; 187 | } -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/app2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5 - TimeComplexity/app2 -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/app2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // logratimic time complexity 8 | 9 | /* 10 | 1000 11 | 12 | log2(1000) 13 | 14 | 2^(x) = 1000 15 | 16 | x = 10 aproximately 17 | */ 18 | 19 | /* 20 | when to say this code runs in a logratimic time complexity 21 | 22 | when the number of steps is reduced by ????? in each iteration 23 | reduced by a number grather than 1 by dividing the number of steps by a number grather than 1 24 | */ 25 | 26 | /* 27 | 1 => n 28 | 2=> n/2 => n/3 . n/4, n/1.5, n/1.1 29 | 3 => n/2 n/3 . n/4, n/1.5, n/1.1 30 | 4 => n/2 n/3 . n/4, n/1.5, n/1.1 31 | 32 | 1 => n => 10 33 | 2 => n/2 => 5 34 | 3 => n/2 => 3 35 | 4 => n/2 => 2 36 | 5 => n/2 => 1 37 | 38 | 39 | n = 100 40 | 41 | 1 => 100 42 | 2 => 50 43 | 3 => 25 44 | 4 => 12 45 | 5 => 6 46 | 6 => 3 47 | 7 => 1 48 | 49 | 50 | binary search 51 | 52 | searches on a sorted array => logratimic time complexity 53 | 54 | is 10 inside the array? 55 | 56 | 1 2 3 4 5 6 7 8 9 10 57 | O(n) => linear search 58 | 59 | array is sorted 60 | 61 | 1. 10 > 8 => 8 is the random index picked 62 | 2. arrays is sorted 63 | 64 | 3=> go the right side 65 | */ 66 | 67 | // factorial 68 | 69 | // long long n = 30; // factorial of 30 is grater that 10^18 70 | 71 | // long long fact = 1; 72 | // for (long long i = 1; i <= n; i++) 73 | // { 74 | // fact *= i; 75 | // } 76 | // cout << fact << endl; 77 | } -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/lib-funcs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5 - TimeComplexity/lib-funcs -------------------------------------------------------------------------------- /Session#5 - TimeComplexity/lib-funcs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // assert 3 | // #include 4 | // #include 5 | #include 6 | // accumulate 7 | #include 8 | using namespace std; 9 | 10 | // char my_to_upper(char small) 11 | // { 12 | // assert(small >= 'a' and small <= 'z'); 13 | // return small - 32; 14 | // } 15 | int main() 16 | { 17 | // cout << my_to_upper('A') << endl; 18 | // sqrt, pow, min,max , floor, ceil, round, 19 | 20 | // floor => rounds down 21 | // ceil => rounds up 22 | 23 | // double useFloor = floor(2.999999); 24 | // double useRound = round(2.6); 25 | // double useCeil = ceil(2.00001); 26 | // cout << "round(2.6) = " << useRound << endl; 27 | // cout << "floor(2.3) = " << useFloor << endl; 28 | // cout << "ceil(2.00001) = " << useCeil << endl; 29 | 30 | // double useSqrt = sqrt(6); // 10 31 | // cout << fixed << setprecision(12); 32 | // cout << "sqrt(6) = " << useSqrt << endl; 33 | 34 | // long long usePow = pow(25, 1 / 2.0); 35 | 36 | // cout << fixed << setprecision(12); 37 | // cout << "pow(2,3) = " << usePow << endl; 38 | 39 | // time complexity of pow function is O(log(n)) 40 | // time complexity of sqrt function is O(log(n)) 41 | 42 | // double x = 10; 43 | // double y = 2; 44 | // // min,max => taks same data types 45 | // double ans = min(x, y); 46 | // cout << "min(10,2) = " << ans << endl; 47 | 48 | // char a = 'a'; 49 | // char b = 'B'; 50 | // char A = toupper(a); 51 | // char B = tolower(b); 52 | 53 | // cout << "toupper(a) = " << A << endl; 54 | // cout << "tolower(B) = " << B << endl; 55 | 56 | // string s = "hello"; 57 | // string caplitalaized = s; 58 | // for (int i = 0; i < s.size(); i++) 59 | // { 60 | // caplitalaized[i] = toupper(s[i]); 61 | // } 62 | // cout << caplitalaized << endl; 63 | 64 | // binary_search 65 | 66 | // binary_search => O(log(n)) 67 | // true => if element is present 68 | // false => if element is not present 69 | 70 | // bool isPresent = binary_search(v.begin(), v.end(), 5); 71 | 72 | // lower_bound => O(log(n)) 73 | // loewr_bound => returns itrator points to the first element graeter than or equal to the target element 74 | 75 | // auto it = lower_bound(v.begin(), v.end(), 5); 76 | // cout << *it << endl; 77 | 78 | // upper_bound => O(log(n)) 79 | // upper_bound => returns itrator points to the first element greater than the target element 80 | 81 | // auto it = upper_bound(v.begin(), v.end(), 5); 82 | 83 | // if (it == v.end()) 84 | // { 85 | // cout << "Element not found" << endl; 86 | // } 87 | // else 88 | // cout << *it << endl; 89 | 90 | // count , acccumulate 91 | 92 | // count => O(n) 93 | // accumulate => O(n) 94 | 95 | // count counts the numbre of occurences of the target element 96 | // accumulate => returns the sum of all the elements in the range 97 | // vector v = {1e9, 1e9, 1e9, 1e9}; 98 | 99 | // cout << accumulate(v.begin(), v.end(), 0ll) << endl; 100 | 101 | // sort => O(nlog(n)) n * log(n) 102 | 103 | // sort(v.begin(), v.end()); // 1 2 3 4 104 | // sort(v.begin(), v.end(), greater()); // 4 3 2 1 105 | // sort(v.rbegin(), v.rend()); // 4 3 2 1 106 | 107 | // find 108 | 109 | // find => O(n) 110 | // search in a non sorted array 111 | // vector v = {2, 2, 3, 4, 5}; 112 | // auto it = find(v.begin(), v.end(), 1); 113 | 114 | // cout << (it - v.begin()) << endl; // if not found then it will return v.end() 115 | } -------------------------------------------------------------------------------- /Session#5/Session#5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5/Session#5.pdf -------------------------------------------------------------------------------- /Session#5/palandrom-number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // string number; 8 | // cin >> number; 9 | 10 | // string numberReverse; 11 | 12 | // for (int i = number.size() - 1; i >= 0; i--) 13 | // numberReverse += number[i]; 14 | 15 | // if (number == numberReverse) 16 | // cout << "Yes"; 17 | // else 18 | // cout << "No"; 19 | 20 | /* 21 | number only three digits 22 | 23 | 24 | */ 25 | // string number; 26 | // cin >> number; 27 | // if (number[0] == number[2]) 28 | // cout << "Yes"; 29 | // else 30 | // cout << "No"; 31 | } 32 | -------------------------------------------------------------------------------- /Session#5/palandrom-number.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5/palandrom-number.exe -------------------------------------------------------------------------------- /Session#5/rining.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | // long long abc[3]; 8 | 9 | // cin >> abc[0] >> abc[1] >> abc[2]; 10 | 11 | // long long min = abc[0]; 12 | // int indexOfMin = 0; 13 | // for (int i = 0; i <= 3 - 1; i++) 14 | // { 15 | // if (abc[i] < min) 16 | // { 17 | // min = abc[i]; 18 | // indexOfMin = i; 19 | // } 20 | // } 21 | // long long min1 = min; 22 | 23 | // abc[indexOfMin] = 1000000000; 24 | // long long min2 = abc[0]; 25 | // for (int i = 0; i < 3; i++) 26 | // { 27 | // if (abc[i] < min2) 28 | // { 29 | // min2 = abc[i]; 30 | // } 31 | // } 32 | 33 | // long long a, b, c; 34 | // cin >> a >> b >> c; 35 | 36 | // long long myMax = max({a, b, c}); 37 | 38 | // cout << (a + b + c) - myMax; 39 | // cout << min1 + min2; 40 | } 41 | -------------------------------------------------------------------------------- /Session#5/substrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | /* 7 | 8 | substring => 9 | 10 | abcdef 11 | 12 | somestring 13 | 14 | a => substring 15 | ab => substring 16 | def => substring 17 | bcdef => substring 18 | abcdef => substring 19 | cde => substring 20 | abc => substring 21 | 22 | 23 | constraints: 24 | s,t => size of s and t is between 1 and 1000, 25 | the size of t is less that or equal to the size of s 26 | s,t is only lowercase letters 27 | 28 | s => cabacc => cabccc 29 | t => abc 30 | 31 | abcacc => 3 32 | 33 | 34 | */ 35 | 36 | string t, s; 37 | cin >> s >> t; 38 | 39 | // int array_size = s.size() - t.size() + 1; 40 | // int arr[array_size]; 41 | /* 42 | cabacc 43 | abc 44 | 0 2 45 | 1 3 46 | 2 4 47 | 3 5 48 | */ 49 | 50 | int count = 0; 51 | int min = 10000000; 52 | for (int i = 0; i <= s.size() - t.size(); i++) 53 | { 54 | for (int x = 0; x < t.size(); x++) 55 | { 56 | if (t[x] != s[i + x]) 57 | { 58 | count++; 59 | } 60 | } 61 | 62 | if (count < min) 63 | min = count; 64 | 65 | count = 0; 66 | } 67 | cout << min; 68 | // int min = arr[0]; 69 | // for (int i = 0; i < array_size; i++) 70 | // { 71 | // if (arr[i] < min) 72 | // { 73 | // min = arr[i]; 74 | // } 75 | // } 76 | // cout << min; 77 | } 78 | -------------------------------------------------------------------------------- /Session#5/substrings.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#5/substrings.exe -------------------------------------------------------------------------------- /Session#6.2/Session#6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6.2/Session#6.pdf -------------------------------------------------------------------------------- /Session#6.2/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6.2/app -------------------------------------------------------------------------------- /Session#6.2/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int itrations = 1e6; 9 | while (itrations--) 10 | { 11 | int n = 1e6; 12 | int *arr = new int[n]; 13 | // some calculations 14 | delete[] arr; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Session#6/Session#6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6/Session#6.pdf -------------------------------------------------------------------------------- /Session#6/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6/main -------------------------------------------------------------------------------- /Session#6/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // struct Name 6 | // { 7 | // int x, y; // x => 4 bytes, y => 4 bytes 8 | // long long z; // 8 bytes 9 | // string st; // 24 bytes 10 | // }; 11 | 12 | int x = 10; // global 13 | 14 | int main() 15 | { 16 | // Name name; 17 | // name.st = "Hello"; 18 | // name.x = 10; 19 | // name.y = 20; 20 | // name.z = 30; 21 | 22 | // Name *ptr = &name; 23 | // cout << "Address of Name: " << ptr << endl; 24 | // cout << "Size of Pointer: " << sizeof(ptr) << endl; 25 | // cout << "Size of Name: " << sizeof(name) << endl; 26 | 27 | // cout << "x = " << x << endl; 28 | // cout << "Address of x = " << &x << endl; 29 | 30 | // int *pointer_to_x = &x; 31 | 32 | // cout << pointer_to_x << endl; 33 | 34 | // // cout << *pointer_to_x << endl; 35 | // cout << "After: " << endl; 36 | // *pointer_to_x = 20; 37 | 38 | // cout << "x = " << x << endl; 39 | // cout << "Address of x = " << &x << endl; 40 | // cout << pointer_to_x << endl; 41 | // cout << *pointer_to_x << endl; 42 | 43 | // // Pointer points to X 44 | // // Value of the Pointer is The Address of X 45 | 46 | /* 47 | Types of Pointers 48 | */ 49 | 50 | // pointer to a type 51 | 52 | // pointer to int, pointer to long long, pointer to string, pointer to vector, 53 | 54 | // double x1 = 10.5; 55 | // long long x2 = 10; 56 | // string x3 = "Hello"; 57 | // int x4 = 10; 58 | 59 | // long long *p2 = &x2; 60 | // string *p3 = &x3; 61 | // double *p1 = &x1; 62 | // int *p4 = &x4; 63 | 64 | // cout << sizeof(p1) << " " << sizeof(x1) << endl; 65 | // cout << sizeof(p2) << " " << sizeof(x2) << endl; 66 | // cout << sizeof(p3) << " " << sizeof(x3) << endl; 67 | // cout << sizeof(p4) << " " << sizeof(x4) << endl; 68 | 69 | // char *ptr = "Hello"; 70 | // cout << ptr << endl; 71 | // // ptr[0] = 'X'; 72 | 73 | // cout << ptr << endl; 74 | 75 | // long long arr[5] = {1, 2, 3, 4, 5}; 76 | // int n = 5; 77 | 78 | // for (int i = 0; i < n; i++) 79 | // { 80 | // cout << arr[i] << " "; 81 | // } 82 | // cout << endl; 83 | 84 | // char *ptr = (char *)arr; 85 | 86 | // long long *endAddress = arr + n; 87 | 88 | // for (char *ptr = (char *)arr; ptr < (char *)endAddress; ptr += sizeof(long long)) 89 | // { 90 | // cout << *((long long *)ptr) << " "; 91 | // } 92 | 93 | // // cout << sizeof(arr) << endl; 94 | // // first number => arr[0] , second number => arr[1], third number => arr[2] 95 | // // cout << &arr[0] << endl; 96 | // cout << *arr << endl; 97 | 98 | /* 99 | new , delete 100 | */ 101 | 102 | // int *ptr = new int(10); 103 | 104 | // cout << ptr << endl; 105 | // delete ptr; 106 | 107 | // ptr = new int(20); 108 | 109 | // cout << ptr << endl; 110 | 111 | // delete ptr; 112 | } 113 | -------------------------------------------------------------------------------- /Session#6/main2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6/main2 -------------------------------------------------------------------------------- /Session#6/main2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int *someFunction() 6 | { 7 | int *x = new int(10); 8 | 9 | return x; 10 | } 11 | 12 | int main() 13 | { 14 | int *ptr = someFunction(); 15 | 16 | if (ptr == nullptr) 17 | { 18 | cout << "Null Pointer" << endl; 19 | } 20 | else 21 | { 22 | cout << "Not Null Pointer" << endl; 23 | cout << *ptr << endl; 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Session#6/meetingAttendanceList.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#6/meetingAttendanceList.csv -------------------------------------------------------------------------------- /Session#7/app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#7/app -------------------------------------------------------------------------------- /Session#7/app.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | /* 6 | what is a class? 7 | class user defined data type 8 | class can have multiple data members 9 | calss can have functions called methods 10 | 11 | 12 | access modifier 13 | public: accessible from anywhere 14 | private: accessible only from within the class 15 | protected: accessible from within the class and derived 16 | 17 | 18 | constructor: special function called when the object is created 19 | 20 | in c++ 21 | 22 | class is by default private 23 | struct is by default public 24 | 25 | 26 | Getters and Setters 27 | 28 | getters : used to get the value of a private data member 29 | setters : used to set the value of a private data member 30 | */ 31 | 32 | class Car 33 | { 34 | private: 35 | string color, brand, model; 36 | double speed; 37 | 38 | public: 39 | Car() 40 | { 41 | // color = "No Color"; 42 | // cout << "Default constructor called" << endl; 43 | } 44 | 45 | Car(string color, string brand = "No Brand", string model = "No Model", double speed = 0) 46 | { 47 | this->color = color; 48 | this->brand = brand; 49 | this->model = model; 50 | this->speed = speed; 51 | } 52 | 53 | void Accelerate() 54 | { 55 | speed += 10; 56 | } 57 | 58 | // getters and setters 59 | 60 | string GetColor() 61 | { 62 | return color; 63 | } 64 | string GetBrand() 65 | { 66 | return brand; 67 | } 68 | 69 | string GetModel() 70 | { 71 | return model; 72 | } 73 | double GetSpeed() 74 | { 75 | return speed; 76 | } 77 | 78 | void SetColor(string color) 79 | { 80 | if (color == "Black") 81 | return; 82 | 83 | this->color = color; 84 | } 85 | void SetSpeed(double speed) 86 | { 87 | if (speed < 0) 88 | return; 89 | 90 | this->speed = speed; 91 | } 92 | 93 | void SetBrand(string brand) 94 | { 95 | this->brand = brand; 96 | } 97 | ~Car() 98 | { 99 | } 100 | }; 101 | 102 | int main() 103 | { 104 | freopen("output.txt", "w", stdout); 105 | // Car car1("red", "toyota", "corolla", 100); 106 | // Car car("Brwon"); 107 | // car.Accelerate(); 108 | // car.SetColor("Black"); 109 | // cout << car.GetColor() << endl; 110 | 111 | // cout << car2.brand << endl; 112 | 113 | /* 114 | objects and pointers 115 | */ 116 | // Car car[10]; 117 | // car[0].SetColor("Red"); 118 | // car[1].SetColor("Blue"); 119 | // car[2].SetColor("Green"); 120 | // car[3].SetColor("Yellow"); 121 | // car[4].SetColor("Black"); 122 | 123 | // for (int i = 0; i < 5; i++) 124 | // { 125 | // cout << car[i].GetColor() << endl; 126 | // } 127 | 128 | // Car *car = new Car("Red", "Toyota", "Corolla", 100); 129 | // cout << car->GetColor() << endl; 130 | // cout << car->GetBrand() << endl; 131 | } -------------------------------------------------------------------------------- /Session#7/app2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#7/app2 -------------------------------------------------------------------------------- /Session#7/app2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | // templates 5 | 6 | template 7 | class Adder 8 | { 9 | public: 10 | T Add(T a, T b) 11 | { 12 | return a + b; 13 | } 14 | }; 15 | 16 | int main() 17 | { 18 | freopen("output.txt", "w", stdout); 19 | 20 | Adder adder; 21 | Adder adder2; 22 | cout << adder2.Add("Hello", "World") << endl; 23 | cout << adder.Add(5, 6) << endl; 24 | } -------------------------------------------------------------------------------- /Session#7/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#7/main -------------------------------------------------------------------------------- /Session#7/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Pizza 5 | { 6 | public: 7 | int size, price, quantity; 8 | string name; 9 | 10 | Pizza(int size = 0, int price = 0, int quantity = 0, string name = "No Name") 11 | { 12 | this->size = size; 13 | this->price = price; 14 | this->quantity = quantity; 15 | this->name = name; 16 | } 17 | ~Pizza() 18 | { 19 | cout << "Pizza " << name << " is destroyed" << endl; 20 | } 21 | }; 22 | class PizzaRestaurant 23 | { 24 | public: 25 | string name; 26 | Pizza *pizzas; 27 | int numberOfAvailablePizzas; 28 | int sizeOfPizzasArray; 29 | PizzaRestaurant(string name = "No Name") 30 | { 31 | pizzas = new Pizza[2]; 32 | sizeOfPizzasArray = 2; 33 | numberOfAvailablePizzas = 0; 34 | this->name = name; 35 | } 36 | void AddPizza(Pizza pizza) 37 | { 38 | 39 | if (numberOfAvailablePizzas < sizeOfPizzasArray) 40 | { 41 | pizzas[numberOfAvailablePizzas] = pizza; 42 | numberOfAvailablePizzas++; 43 | } 44 | else 45 | { 46 | sizeOfPizzasArray = sizeOfPizzasArray * 2; 47 | Pizza *newPizzas = new Pizza[sizeOfPizzasArray * 2]; 48 | for (int i = 0; i < numberOfAvailablePizzas; i++) 49 | { 50 | newPizzas[i] = pizzas[i]; 51 | } 52 | 53 | newPizzas[numberOfAvailablePizzas] = pizza; 54 | numberOfAvailablePizzas++; 55 | 56 | delete[] pizzas; 57 | pizzas = newPizzas; 58 | } 59 | } 60 | void GetPizzas() 61 | { 62 | for (int i = 0; i < numberOfAvailablePizzas; i++) 63 | { 64 | if (pizzas[i].name != "No Name") 65 | { 66 | cout << "Name: " << pizzas[i].name << endl; 67 | cout << "Size: " << pizzas[i].size << endl; 68 | cout << "Price: " << pizzas[i].price << endl; 69 | cout << "Quantity: " << pizzas[i].quantity << endl; 70 | cout << "--------------------------\n"; 71 | } 72 | else 73 | { 74 | break; 75 | } 76 | } 77 | } 78 | ~PizzaRestaurant() 79 | { 80 | delete[] pizzas; 81 | } 82 | }; 83 | 84 | int main() 85 | { 86 | freopen("output.txt", "w", stdout); 87 | 88 | PizzaRestaurant resturant("Some Resturant"); 89 | resturant.AddPizza(Pizza(30, 100, 2, "Margarita")); 90 | resturant.AddPizza(Pizza(40, 150, 1, "Pepperoni")); 91 | resturant.AddPizza(Pizza(50, 200, 3, "Hawaiian")); 92 | resturant.AddPizza(Pizza(60, 250, 4, "BBQ")); 93 | resturant.AddPizza(Pizza(70, 300, 5, "Cheese")); 94 | // resturant.GetPizzas(); 95 | } -------------------------------------------------------------------------------- /Session#7/output.txt: -------------------------------------------------------------------------------- 1 | HelloWorld 2 | 11 3 | -------------------------------------------------------------------------------- /Session#8/linked-list: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devsCommunity23/problem-solving-course/b5063477f7a39f7801fde82492c5fe02ff0f9e12/Session#8/linked-list -------------------------------------------------------------------------------- /Session#8/linked-list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Node 5 | { 6 | int data; 7 | Node *next; 8 | 9 | Node() 10 | { 11 | this->data = 0; 12 | this->next = nullptr; 13 | } 14 | Node(int data, Node *next = nullptr) : data(data), next(next) {} 15 | 16 | ~Node() 17 | { 18 | 19 | cout << "Deleting Node with data: " << data << endl; 20 | if (next != nullptr) 21 | { 22 | delete next; 23 | } 24 | } 25 | }; 26 | 27 | class LinkedList 28 | { 29 | Node *head, *tail; 30 | 31 | public: 32 | void insert(int value) 33 | { 34 | Node *newNode = new Node(value); 35 | if (head == nullptr) 36 | { 37 | head = newNode; 38 | tail = head; 39 | } 40 | else 41 | { 42 | tail->next = newNode; 43 | tail = newNode; 44 | } 45 | } 46 | 47 | void deleteFromList(int value) 48 | { 49 | if (head != nullptr and head->data == value) 50 | { 51 | Node *temp = head->next; 52 | head->next = nullptr; 53 | 54 | delete head; 55 | 56 | head = temp; 57 | 58 | return; 59 | } 60 | Node *curr = head; 61 | while (curr != nullptr and curr->next != nullptr) 62 | { 63 | if (curr->next->data == value) 64 | { 65 | Node *temp = curr->next->next; // store reference to the remaiing list 66 | 67 | // cout << temp << " " << curr->next->next << endl; 68 | // cout << "DATA IS :" << curr->next->next->data << endl; 69 | // cout << "TEMP IS :" << temp->data << endl; 70 | if (curr->next == tail) 71 | tail = curr; 72 | // if the node to be deleted is the last node 73 | 74 | curr->next->next = nullptr; // cut the link 75 | 76 | delete curr->next; // delete the node 77 | curr->next = temp; // link the remaining list 78 | return; 79 | } 80 | curr = curr->next; 81 | } 82 | } 83 | 84 | void print() 85 | { 86 | auto temp = head; 87 | while (temp != nullptr) 88 | { 89 | cout << temp->data << " "; 90 | temp = temp->next; 91 | } 92 | cout << endl; 93 | } 94 | 95 | ~LinkedList() 96 | { 97 | if (head != nullptr) 98 | delete head; 99 | } 100 | }; 101 | 102 | int main() 103 | { 104 | LinkedList list; 105 | list.insert(1); 106 | list.insert(2); 107 | list.insert(3); 108 | list.insert(4); 109 | list.print(); 110 | 111 | list.deleteFromList(2); 112 | cout << "------------------------" << endl; 113 | list.deleteFromList(4); 114 | cout << "------------------------" << endl; 115 | // list.insert(5); 116 | // list.insert(6); 117 | 118 | // list.print(); 119 | } -------------------------------------------------------------------------------- /Session#Stack/Stack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Stack 6 | { 7 | private: 8 | int *data; 9 | int size; 10 | int currentIndex; 11 | 12 | void checkIndex() 13 | { 14 | if (currentIndex == 0) 15 | { 16 | cout << "Stack is empty" << endl; 17 | exit(1); 18 | } 19 | } 20 | 21 | public: 22 | Stack() 23 | { 24 | size = 4; 25 | data = new int[size]; 26 | currentIndex = 0; 27 | } 28 | 29 | void push(int value) 30 | { 31 | if (currentIndex == size) 32 | { 33 | int *newData = new int[size * 2]; 34 | for (int i = 0; i < size; i++) 35 | newData[i] = data[i]; 36 | 37 | delete[] data; 38 | 39 | data = newData; 40 | } 41 | data[currentIndex] = value; 42 | currentIndex++; 43 | } 44 | void pop() 45 | { 46 | checkIndex(); 47 | currentIndex--; 48 | } 49 | int top() 50 | { 51 | checkIndex(); 52 | return data[currentIndex - 1]; 53 | } 54 | bool empty() 55 | { 56 | return currentIndex == 0; 57 | } 58 | }; 59 | bool check(const string &sequnce) 60 | { 61 | Stack s; 62 | 63 | for (int i = 0; i < sequnce.size(); i++) 64 | { 65 | if (sequnce[i] == '(') 66 | s.push(i); 67 | else if (sequnce[i] == ')') 68 | { 69 | if (s.empty()) 70 | return false; 71 | s.pop(); 72 | } 73 | } 74 | 75 | return s.empty(); 76 | } 77 | 78 | vector make_next_grater(const vector &v) 79 | { 80 | 81 | Stack st; 82 | 83 | vector ans(v.size(), -1); 84 | 85 | for (int i = 0; i < v.size(); i++) 86 | { 87 | while (not st.empty() and v[i] > v[st.top()]) 88 | { 89 | ans[st.top()] = v[i]; 90 | 91 | st.pop(); 92 | } 93 | 94 | st.push(i); 95 | } 96 | 97 | return ans; 98 | } 99 | 100 | int main() 101 | { 102 | } --------------------------------------------------------------------------------