├── .DS_Store ├── Lecture 6 ├── pass_by_reference_using_pointers ├── pass_by_reference_using_pointers.cpp ├── pointer ├── pointer.cpp ├── reference_fn ├── reference_fn.cpp ├── reference_variable ├── reference_variable.cpp ├── return_by_reference └── return_by_reference.cpp ├── Lecture-2 (Loops) ├── .DS_Store ├── bill_calc.cpp ├── factorial.cpp ├── for_loop.cpp ├── main_mystery.cpp └── pattern.cpp ├── Lecture-3 (Functions) ├── abcd_pattern ├── abcd_pattern.cpp ├── fix1 ├── fix1.cpp ├── fix2 ├── fix2.cpp ├── loop_break ├── loop_break.cpp ├── pass_by_value ├── pass_by_value.cpp ├── play_song ├── play_song.cpp ├── prime_print ├── prime_print.cpp ├── print_all_prime ├── print_all_prime.cpp ├── reference_variables └── reference_variables.cpp ├── Lecture-4 (Arrays) ├── array_basic ├── array_basic.cpp ├── binary_search ├── binary_search.cpp ├── linear_search ├── linear_search.cpp ├── pairs ├── pairs.cpp ├── square_root └── square_root.cpp ├── Lecture-7 Recursion ├── factorial ├── factorial.cpp ├── increasing_dec ├── increasing_dec.cpp ├── ladder ├── ladder.cpp ├── power ├── power.cpp └── untitled ├── fact ├── fact.cpp ├── homework.txt ├── maximum_subarray_sum ├── maximum_subarray_sum.cpp ├── three_sum ├── three_sum.cpp └── untitled /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/.DS_Store -------------------------------------------------------------------------------- /Lecture 6/pass_by_reference_using_pointers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/Lecture 6/pass_by_reference_using_pointers -------------------------------------------------------------------------------- /Lecture 6/pass_by_reference_using_pointers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //pass by reference using pointers 5 | void incrementMoney(int *money){ 6 | *money = *money + 10; 7 | } 8 | 9 | 10 | int main(){ 11 | 12 | int m = 10; 13 | incrementMoney(&m); 14 | cout << m < 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | 7 | 8 | int x = 10; 9 | //Address of operator 10 | cout << &x < 2 | using namespace std; 3 | 4 | //passing views by reference 5 | void incrementViewCnt(int &views){ 6 | views++; 7 | } 8 | 9 | int main(){ 10 | 11 | int videoViews = 1001; 12 | incrementViewCnt(videoViews); 13 | 14 | cout << videoViews < 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | 7 | //Reference Variable 8 | int x = 10; 9 | int &y = x; 10 | 11 | x++; 12 | 13 | cout<< x < 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | 7 | int *b = createArray(); 8 | 9 | cout << b[0] < 2 | using namespace std; 3 | 4 | /* 5 | 1 to 100 units Free 6 | 100 to 200 units Rs. 5/unit 7 | 200 to 300 units Rs.10/unit 8 | 300+ units Rs.12/unit 9 | */ 10 | 11 | int main(){ 12 | 13 | int units; 14 | cin>>units; 15 | 16 | int bill_amount; 17 | 18 | if(units<=100){ 19 | bill_amount = 0; 20 | } 21 | else if(units<=200){ 22 | bill_amount = (units-100)*5; 23 | } 24 | else if(units<=300){ 25 | bill_amount = (100*5) + (units-200)*10; 26 | } 27 | else{ 28 | bill_amount = (100*5) + (100*10) + (units-300)*12; 29 | } 30 | cout << bill_amount < 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | int n; 9 | cin>>n; 10 | 11 | int x = 1; 12 | int ans = 1; //an array to store 13 | 14 | while(x<=n){ 15 | 16 | ans = ans*x; 17 | 18 | x++; 19 | } 20 | 21 | cout << "Product is "< 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | int n; 9 | cin>>n; 10 | 11 | int ans =1; 12 | 13 | for(int x=1; x<=n; x = x+1){ 14 | //Repeat 15 | ans = ans*x; 16 | } 17 | 18 | cout << "Product is "< 2 | using namespace std; 3 | 4 | /* This is 5 | a 6 | multiple line 7 | comment 8 | */ 9 | 10 | void sayHello(); //Declaration 11 | 12 | 13 | void sayHello(){ //Declaration + Definition 14 | cout<<"Hello Everyone!"; 15 | } 16 | 17 | int main(){ 18 | 19 | sayHello(); //Function Call; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Lecture-2 (Loops)/pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | int n; 9 | cin>>n; 10 | 11 | int value = 1; 12 | 13 | for(int row=1;row<=n;row=row+1){ 14 | for(int cnt=1;cnt<=row;cnt=cnt+1){ 15 | cout< 2 | using namespace std; 3 | 4 | /* 5 | ABCDEEDCBA 6 | ABCDDCBA 7 | ABCCBA 8 | ABBA 9 | AA 10 | */ 11 | 12 | 13 | int main(){ 14 | 15 | int n; 16 | cin>>n; 17 | //rows 18 | for(int row=1;row<=n;row++){ 19 | 20 | int cnt = n - row + 1; 21 | char value = 'A'; 22 | //inc 23 | for(int c=1;c<=cnt;c++){ 24 | cout < 2 | using namespace std; 3 | 4 | int increment(int money){ 5 | money = money + 10; 6 | return money; 7 | } 8 | 9 | 10 | 11 | 12 | int main(){ 13 | int money; 14 | cin>>money; //10 15 | money = increment(money); 16 | cout < 2 | using namespace std; 3 | 4 | //pass by reference using reference variable 5 | void increment(int &pese){ 6 | pese = pese + 10; 7 | } 8 | 9 | 10 | int main(){ 11 | int money; 12 | cin>>money; //10 13 | increment(money); 14 | cout<< money; //20 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Lecture-3 (Functions)/loop_break: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/Lecture-3 (Functions)/loop_break -------------------------------------------------------------------------------- /Lecture-3 (Functions)/loop_break.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | int n; 9 | cin>>n; 10 | 11 | int i; 12 | for(i=1; i<=n ; i++){ 13 | 14 | if(i%7==0){ 15 | continue; 16 | } 17 | cout< 2 | using namespace std; 3 | 4 | void increment(int money){ 5 | money = money + 10; 6 | } 7 | 8 | 9 | 10 | 11 | int main(){ 12 | int money; 13 | cin>>money; //10 14 | increment(money); 15 | cout < 2 | #include 3 | using namespace std; 4 | 5 | void play_song(string type,int duration=5){ 6 | cout<<"Playing a "<>song_type; 12 | 13 | int time; 14 | cin>>time; 15 | 16 | play_song(song_type,time); 17 | 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Lecture-3 (Functions)/prime_print: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/Lecture-3 (Functions)/prime_print -------------------------------------------------------------------------------- /Lecture-3 (Functions)/prime_print.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //17 5 | 6 | bool isPrime(int number){ 7 | 8 | for(int i=2;i<=number-1;i++){ 9 | if(number%i==0){ 10 | return false; 11 | } 12 | } 13 | return true; 14 | } 15 | 16 | 17 | int main(){ 18 | 19 | int no; 20 | cin>>no; 21 | 22 | if(isPrime(no)){ 23 | cout< 2 | using namespace std; 3 | 4 | bool isPrime(int number){ 5 | 6 | for(int i=2;i<=number-1;i++){ 7 | if(number%i==0){ 8 | return false; 9 | } 10 | } 11 | return true; 12 | } 13 | 14 | void printAllPrime(int N){ 15 | 16 | for(int no=2;no<=N;no++){ 17 | if(isPrime(no)){ 18 | cout<>N; 28 | printAllPrime(N); 29 | 30 | return 5; 31 | } -------------------------------------------------------------------------------- /Lecture-3 (Functions)/reference_variables: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/Lecture-3 (Functions)/reference_variables -------------------------------------------------------------------------------- /Lecture-3 (Functions)/reference_variables.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main(){ 6 | //Reference Variables 7 | 8 | int x = 10; 9 | int &y = x; 10 | 11 | y = y*10; 12 | 13 | x += 10; 14 | 15 | cout<< x < 2 | using namespace std; 3 | 4 | // 1. Arrays are passed by reference 5 | // 2. You should pass N 6 | 7 | void print(int arr[],int n){ 8 | 9 | arr[2] = 20; 10 | for(int i=0;i largest){ 28 | largest = arr[i]; 29 | } 30 | } 31 | return largest; 32 | } 33 | 34 | 35 | 36 | int main(){ 37 | 38 | int arr[] = {10,15,12,13,26,8}; 39 | int n = sizeof(arr)/sizeof(int); //6 40 | 41 | cout<< findLargest(arr,n) < 2 | using namespace std; 3 | 4 | //Binary Search 5 | int binary_search(int a[],int n,int X){ 6 | int s = 0; 7 | int e = n -1; 8 | 9 | while(s<=e){ 10 | int mid = (s+e)/2; 11 | 12 | if(a[mid]==X){ 13 | return mid; 14 | } 15 | else if(a[mid]>X){ 16 | e = mid - 1; 17 | } 18 | else{ 19 | s = mid + 1; 20 | } 21 | } 22 | return -1; 23 | } 24 | 25 | 26 | int main(){ 27 | //Sorted Array 28 | int arr[] = {1,2,10,11,19,29,38}; 29 | int n = sizeof(arr)/sizeof(int); 30 | 31 | int X; 32 | cin>>X; 33 | 34 | cout<<"Binary Searching ..."< 2 | using namespace std; 3 | 4 | 5 | int linearSearch(int arr[],int n,int X){ 6 | 7 | for(int i=0;i 2 | using namespace std; 3 | 4 | 5 | void twoSum(int arr[],int n,int X){ 6 | for(int i=0;i 2 | using namespace std; 3 | 4 | int squareRoot(int N){ 5 | //Linear Search 6 | int i; 7 | for(i=0; i*i <=N;i++){} 8 | 9 | return i-1; 10 | } 11 | 12 | //--------------Binary Search 13 | int sqRootBinSearch(int N){ 14 | 15 | int s =0; 16 | int e = N; 17 | 18 | int ans = 0; 19 | 20 | while(s<=e){ 21 | int mid = (s+e)/2; 22 | 23 | if(mid*mid==N){ 24 | return mid; 25 | } 26 | else if(mid*mid < N){ 27 | ans = mid; 28 | s = mid + 1; 29 | } 30 | else{ 31 | e = mid - 1; 32 | } 33 | } 34 | return ans; 35 | 36 | } 37 | 38 | int main(){ 39 | 40 | int N; 41 | cin>>N; 42 | cout << squareRoot(N)< 10 45 | ///110-->10 46 | ///121 -->11 47 | //50 ---?7 48 | //49---> 7 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Lecture-7 Recursion/factorial: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/Lecture-7 Recursion/factorial -------------------------------------------------------------------------------- /Lecture-7 Recursion/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int factorial(int n){ 6 | //base case 7 | if(n==0){ 8 | return 1; 9 | } 10 | 11 | //rec case 12 | return n*factorial(n-1); 13 | } 14 | 15 | 16 | int main(){ 17 | int n ; 18 | cin>>n; 19 | cout << factorial(n) < 2 | using namespace std; 3 | 4 | 5 | void inc(int n){ 6 | 7 | 8 | if(n==0){ 9 | return; 10 | } 11 | 12 | 13 | inc(n-1); 14 | cout << n < 2 | using namespace std; 3 | 4 | 5 | int f(int n){ 6 | 7 | if(n==0){ 8 | return 1; 9 | } 10 | if(n<0){ 11 | return 0; 12 | } 13 | return f(n-1) + f(n-2) + f(n-3); 14 | 15 | } 16 | 17 | 18 | int main(){ 19 | 20 | int n; 21 | cin>>n; 22 | cout << f(n) < 2 | using namespace std; 3 | 4 | 5 | int power(int a,int b){ 6 | if(b==0){ 7 | return 1; 8 | } 9 | //rec case 10 | return a*power(a,b-1); 11 | } 12 | 13 | 14 | int fastpower(int a,int n){ 15 | if(n==0){ 16 | return 1; 17 | } 18 | 19 | int smallAns = power(a,n/2); 20 | smallAns = smallAns*smallAns; 21 | 22 | if(n%2==0){ 23 | //n is even 24 | return smallAns; 25 | } 26 | 27 | return a * smallAns; 28 | 29 | } 30 | 31 | 32 | 33 | int main(){ 34 | 35 | int a,b; 36 | cin>> a >>b; 37 | 38 | cout << fastpower(a,b) < 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | 9 | int f = 1; 10 | for(int i=1;i<=10;i++){ 11 | f = f*i; 12 | } 13 | 14 | cout<< f < 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | 8 | 9 | //Kadane's Algorithm (Intutive) 10 | int arr[] = {-1,2,3,-5,6,-1,10,12,-4,-3}; 11 | int n = sizeof(arr)/sizeof(int); 12 | 13 | 14 | int cs = 0; 15 | int ms = 0; 16 | 17 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | 6 | 7 | int main(){ 8 | 9 | 10 | int arr[] = {10,12,1,5,6,2,3,8,7,5,0}; 11 | 12 | int n = sizeof(arr)/sizeof(int); 13 | 14 | int T; 15 | cin>>T; 16 | 17 | 18 | 19 | //Sort 20 | sort(arr,arr + n); 21 | 22 | int current_sum ; 23 | 24 | for(int i=0;i<=n-3;i++){ 25 | //for every a[i] we need to find a pair such a[i] + P1 + P2 === T 26 | int j = i + 1; 27 | int k = n - 1; 28 | 29 | while(jT){ 37 | k--; 38 | } 39 | else{ 40 | j++; 41 | } 42 | 43 | } 44 | } 45 | 46 | 47 | 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /untitled: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateek27/interwell-coding-basic-bootcamp/b1b558e215f4d493dbe93c63d0d1544663d17785/untitled --------------------------------------------------------------------------------