├── .github └── ISSUE_TEMPLATE │ └── custom.md ├── Address_Typecasting.cpp ├── All_Indices_of_Number.cpp ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Check_number.cpp ├── Clear All Bits From MSB.cpp ├── Collecting the balls.cpp ├── Crossword Problem.cpp ├── Different Names.cpp ├── Duplicate_in_array.cpp ├── Even_and_Odd_Indixes.cpp ├── Extract Unique characters.cpp ├── Find first set bit.cpp ├── Find power of a number.cpp ├── Find_the_Unique_Element.cpp ├── First_Index_of_Number.cpp ├── LICENSE ├── Last_Index_of_Number.cpp ├── Longest consecutive Sequence.cpp ├── Love_for_Characters.cpp ├── N-Queen Problem.cpp ├── Notes ├── pointers.pdf └── recursion.pdf ├── Number_of_Digits.cpp ├── Pair sum to 0.cpp ├── Power.cpp ├── Prerequisites ├── Oscillating_Prices_of_Chakri.cpp ├── PRE4.cpp ├── Sum_Array.cpp └── Target_Marbles.cpp ├── Print_numbers.cpp ├── Quiz ├── 2D_arrays ├── Address_of_Variable ├── Address_of_variable ├── Check ith bit ├── Constants ├── Constants2 ├── Constants3 ├── Constants4 ├── Create_Array ├── Create_array2 ├── Deallocate_memory ├── Deallocate_memory2 ├── Default_arguments ├── Delete_2D_array ├── Delete_array ├── Delete_memory ├── Dynamic_Memory_allocation ├── Dynamic_Memory_allocation2 ├── Dynamic_Memory_allocation3 ├── Efficiency of an Algorithm ├── Fibonacci ├── Fibonacci2 ├── Fill_the_output ├── Fill_the_output2 ├── Fill_the_output3 ├── Fill_the_output4 ├── Fill_the_output5 ├── Fill_the_output6 ├── Fill_the_output7 ├── Fill_the_output8 ├── Fill_the_output9 ├── Inline_functions ├── InsertionSort Worst Case Time Complexity ├── Jagged_array ├── Linear Search ├── Linear Search Worst Case ├── Merge Sort space ├── Merge sort ├── Operations for merging ├── Pointer_Declaration ├── Pointers_Output ├── Pointers_Output2 ├── Pointers_Output3 ├── Pointers_Output4 ├── Pointers_Output5 ├── Pointers_Output6 ├── Pointers_Output7 ├── Pointers_Output8 ├── Predict The Output ├── Predict The Output2 ├── Predict The Output3 ├── Predict The Output4 ├── Predict The Output5 ├── Recurrence for Merge Sort ├── Reference_variable ├── Selection Sort ├── Theoretical Analysis ├── Time Complexity ├── Time Complexity of Code ├── Time Complexity of Code2 ├── Turn Off The Bit ├── Turn Off The Bit2 ├── What is time complexity ├── What is time complexity2 ├── What_is_the_output10 ├── What_is_the_output11 ├── What_is_the_output12 ├── What_is_the_output13 ├── What_is_the_output14 ├── What_is_the_output15 ├── What_is_the_output16 ├── What_is_the_output17 ├── What_is_the_output2 ├── What_is_the_output3 ├── What_is_the_output4 ├── What_is_the_output5 ├── What_is_the_output6 ├── What_is_the_output7 ├── What_is_the_output8 ├── What_is_the_output9 ├── What_is_the_output? ├── What_will_be_the_output? ├── What_will_be_the_output?2 ├── What_will_be_the_output?3 ├── What_will_be_the_output?4 ├── What_will_be_the_output?5 ├── What_will_be_the_output?6 ├── What_will_be_the_output?7 └── void_pointer ├── README.md ├── Rat In A Maze Problem.cpp ├── Rotate_array.cpp ├── Set ith bit.cpp ├── Sorting the Skills.cpp ├── Sudoku Solver.cpp ├── Sum me Up.cpp ├── Sum_of_Array.cpp ├── Tell the positions.cpp ├── Triplet sum.cpp ├── Turn off 1st set bit.cpp ├── Unset ith bit.cpp └── Warm Reception.cpp /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /Address_Typecasting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int i = 65; 6 | char c = i; 7 | cout << c << endl; 8 | 9 | int * p = &i; 10 | char * pc = (char*)p; 11 | 12 | cout << p << endl; 13 | cout << pc << endl; 14 | 15 | cout << *p << endl; 16 | cout << *pc << endl; 17 | cout << *(pc + 1) << endl; 18 | cout << *(pc + 2) << endl; 19 | cout << *(pc + 3) << endl; 20 | } 21 | -------------------------------------------------------------------------------- /All_Indices_of_Number.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 3 | 4 | Given an array of length N and an integer x, you need to find all the indexes where x is present in the input array. Save all the indexes in an array (in increasing order). 5 | Do this recursively. Indexing in the array starts from 0. 6 | Input Format : 7 | Line 1 : An Integer N i.e. size of array 8 | Line 2 : N integers which are elements of the array, separated by spaces 9 | Line 3 : Integer x 10 | Output Format : 11 | indexes where x is present in the array (separated by space) 12 | Constraints : 13 | 1 <= N <= 10^3 14 | Sample Input : 15 | 5 16 | 9 8 10 8 8 17 | 8 18 | Sample Output : 19 | 1 3 4 20 | CODE: 21 | */ 22 | 23 | 24 | int allIndexes(int input[], int size, int x, int output[]) { 25 | 26 | if (size == 0) { 27 | return 0; 28 | } 29 | 30 | // Getting the recursive answer 31 | int smallAns = allIndexes(input + 1, 32 | size - 1, x, output); 33 | 34 | 35 | if (input[0] == x) { 36 | for (int i = smallAns - 1; i >= 0; i--) { 37 | output[i + 1] = output[i] + 1; 38 | } 39 | 40 | output[0] = 0; 41 | smallAns++; 42 | } 43 | else { 44 | 45 | for (int i = smallAns - 1; i >= 0; i--) { 46 | output[i] = output[i] + 1; 47 | } 48 | } 49 | return smallAns; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at amangupta884036@protonmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # To Collaborate and contribute: 3 | 4 | 1. Fork the repository to your own GitHub account. 5 | 6 | 2. Clone the repository to your local machine 7 | ``` 8 | $ git clone "https://www.github.com//Codezen.git" 9 | ``` 10 | 3. Create a branch where you can do your local work. 11 | 12 | ``` 13 | $ git branch 14 | $ git checkout 15 | ``` 16 | 17 | 4. Do your work and stage your changes. 18 | ``` 19 | $ git add 20 | ``` 21 | 22 | 5. Commit you changes with a commit message containing your name, file(s) worked upon and the changes added. 23 | ``` 24 | $ git commit -m "Name| files| Changes" 25 | ``` 26 | 27 | 6. Push changes to your forked repository 28 | ``` 29 | $ git push -u origin branchname 30 | ``` 31 | 7. Create a pull request to the upstream repository. 32 | 33 | # Synchronize forked repository with this repository 34 | 35 | 1. Create a remote upstream for this repository 36 | ``` 37 | $ git remote add upstream "https://github.com/Aman9026/Codezen" 38 | ``` 39 | 40 | 2. Fetch upstream changes in local machine 41 | ``` 42 | $ git fetch upstream 43 | ``` 44 | 45 | 3. Switch to master branch 46 | ``` 47 | $ git checkout master 48 | ``` 49 | 50 | 4. Merge changes in local machine 51 | ``` 52 | $ git merge upstream/master 53 | ``` 54 | 55 | 5. Push changes to your forked GitHub repository 56 | ``` 57 | $ git push -f origin master 58 | -------------------------------------------------------------------------------- /Check_number.cpp: -------------------------------------------------------------------------------- 1 | /*Given an array of length N and an integer x, you need to find if x is present in the array or not. Return true or false. 2 | Do this recursively. 3 | Input Format : 4 | Line 1 : An Integer N i.e. size of array 5 | Line 2 : N integers which are elements of the array, separated by spaces 6 | Line 3 : Integer x 7 | Output Format : 8 | true or false 9 | Constraints : 10 | 1 <= N <= 10^3 11 | Sample Input : 12 | 3 13 | 9 8 10 14 | 8 15 | Sample Output : 16 | true 17 | */ 18 | bool checkNumber(int input[], int size, int x) { 19 | for(int i=0;i 38 | 39 | using namespace std; 40 | 41 | long long helper(long long start, long long end, long long N, long long &ans){ 42 | // cout << "start: "< end) 46 | { 47 | return ans; 48 | } 49 | 50 | long long n = N; 51 | 52 | long long mid = (start+end)/2; 53 | //cout << "mid; "<=k && n>0){ 60 | sharma += k; 61 | n = n-k; 62 | singh += (n)/10; 63 | n = n-(n)/10; 64 | } 65 | 66 | sharma += n; 67 | // cout << "sharma: " <>n; 94 | 95 | cout << helper(1, n, n, n) << '\n'; 96 | 97 | 98 | return 0 ; 99 | 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Crossword Problem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | CodingNinjas has provided a crossword of 10*10 grid. The grid contains '+' or '-' as its cell values. Now, you are also provided with a word list that needs to placed accurately in the grid. Cells marked with '-' are to be filled with word list. 5 | For example, The following is an example for the input crossword grid and the word list. 6 | +-++++++++ 7 | +-++-+++++ 8 | +-------++ 9 | +-++-+++++ 10 | +-++-+++++ 11 | +-++-+++++ 12 | ++++-+++++ 13 | ++++-+++++ 14 | ++++++++++ 15 | ---------- 16 | CALIFORNIA;NIGERIA;CANADA;TELAVIV 17 | Output for the given input should be: 18 | +C++++++++ 19 | +A++T+++++ 20 | +NIGERIA++ 21 | +A++L+++++ 22 | +D++A+++++ 23 | +A++V+++++ 24 | ++++I+++++ 25 | ++++V+++++ 26 | ++++++++++ 27 | CALIFORNIA 28 | Note: We have provided such test cases that there is only one solution for the given input. 29 | Input format: 30 | The first 10 lines of input contain crossword. Each of 10 lines has a character array of size 10. Input characters are either '+' or '-'. 31 | The next line of input contains the word list, in which each word is separated by ';'. 32 | Output format: 33 | Print the crossword grid, after placing the words of word list in '-' cells. 34 | Sample Test Cases: 35 | Sample Input 1: 36 | +-++++++++ 37 | +-++-+++++ 38 | +-------++ 39 | +-++-+++++ 40 | +-++-+++++ 41 | +-++-+++++ 42 | ++++-+++++ 43 | ++++-+++++ 44 | ++++++++++ 45 | ---------- 46 | CALIFORNIA;NIGERIA;CANADA;TELAVIV 47 | Sample Output 1: 48 | +C++++++++ 49 | +A++T+++++ 50 | +NIGERIA++ 51 | +A++L+++++ 52 | +D++A+++++ 53 | +A++V+++++ 54 | ++++I+++++ 55 | ++++V+++++ 56 | ++++++++++ 57 | CALIFORNIA 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | CODE: 66 | */ 67 | 68 | 69 | #include 70 | using namespace std; 71 | char crossWord[10][10]; 72 | 73 | bool isValidHorizontal(int row, int col, string word){ 74 | 75 | if(10 - col < word.length()) 76 | return false; 77 | 78 | for (int i = 0, j = col; i < word.length(); ++i,j++) 79 | { 80 | if (crossWord[row][j] != '-' && crossWord[row][j] != word[i]){ 81 | return false; 82 | } 83 | } 84 | 85 | return true; 86 | } 87 | 88 | bool isValidVertical(int row, int col, string word){ 89 | 90 | if(10 - row < word.length()) 91 | return false; 92 | 93 | for (int i = row, j = 0; j < word.length(); ++i,j++) 94 | { 95 | if (crossWord[i][col] != '-' && crossWord[i][col] != word[j]){ 96 | return false; 97 | } 98 | } 99 | 100 | return true; 101 | } 102 | 103 | void setHorizontal(int row, int col, string word, bool state[]){ 104 | 105 | for (int i = 0, j = col; i < word.size(); ++i, j++) 106 | { 107 | if (crossWord[row][j] != '+'){ 108 | 109 | if(crossWord[row][j] == word[i]) 110 | state[i] = false; 111 | else 112 | state[i] = true; 113 | crossWord[row][j] = word[i]; 114 | } 115 | 116 | } 117 | } 118 | 119 | void setVertical(int row, int col, string word, bool state[]){ 120 | 121 | for (int i = 0, j = row; i < word.size(); ++i, j++) 122 | { 123 | if (crossWord[j][col] != '+'){ 124 | 125 | if(crossWord[j][col] == word[i]) 126 | state[i] = false; 127 | else 128 | state[i] = true; 129 | crossWord[j][col] = word[i]; 130 | } 131 | 132 | } 133 | } 134 | 135 | void resetHorizontal(int row, int col, bool state[], int size){ 136 | 137 | for (int i = 0, j = col; i < size; ++i,j++) 138 | { 139 | if(state[i] == true) 140 | crossWord[row][j] = '-'; 141 | } 142 | return; 143 | } 144 | 145 | void resetVertical(int row, int col, bool state[], int size){ 146 | 147 | for (int i = 0, j = row; i < size; ++i,j++) 148 | { 149 | if(state[i] == true) 150 | crossWord[j][col] = '-'; 151 | } 152 | return; 153 | } 154 | 155 | void set_value(bool helper[],int len ){ 156 | for(int i=0;i>ss; 215 | for(int j = 0; j < ss.size(); j++){ 216 | crossWord[i][j] = ss[j]; 217 | } 218 | } 219 | 220 | char s[200]; 221 | cin >> s; 222 | 223 | string input[10]; 224 | char ch; 225 | string word =""; 226 | int a =0; 227 | for (int i = 0; s[i] != '\0'; ++i) 228 | { 229 | 230 | if(s[i] == ';'){ 231 | input[a++] = word; 232 | word =""; 233 | } 234 | else { 235 | word += s[i]; 236 | } 237 | } 238 | input[a++] = word; 239 | 240 | solveCrossWord(input, a); 241 | return 0; 242 | } 243 | -------------------------------------------------------------------------------- /Different Names.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | In Little Flowers Public School, there are many students with same first names. You are given a task to find the students with same names. You will be given a string comprising of all the names of students and you have to tell the name and count of those students having same. If all the names are unique, print -1 instead. 5 | Note: We don't have to mention names whose frequency is 1. 6 | Input Format: 7 | The only line of input will have a string ‘str’ with space separated first names of students. 8 | Output Format: 9 | Print the names of students along with their count if they are repeating. If no name is repeating, print -1 10 | Constraints: 11 | 1 <= |str| <= 10^5 12 | Time Limit: 1 second 13 | Sample Input 1: 14 | Abhishek harshit Ayush harshit Ayush Iti Deepak Ayush Iti 15 | Sample Output 1: 16 | harshit 2 17 | Ayush 3 18 | Iti 2 19 | Sample Input 2: 20 | Abhishek Harshit Ayush Iti 21 | Sample Output: 22 | -1 23 | 24 | 25 | CODE: 26 | 27 | */ 28 | 29 | #include 30 | using namespace std; 31 | int main (){ 32 | string s; 33 | int count=0; 34 | // Taking input string from user 35 | getline(cin,s); 36 | // Taking an empty string temp 37 | string temp=""; 38 | // Defining map 39 | unordered_map m; 40 | for(int i=0;i::iterator it; 54 | for(it=m.begin();it!=m.end();it++){ 55 | if(it->second>=2){ 56 | // Printing the repeated names along with their frequency 57 | cout<first<<" "<second< 26 | using namespace std; 27 | int main() 28 | { 29 | int n=0,even=0,odd=0; 30 | cin>>n; 31 | int arr[n]; 32 | for(int i=0;i>arr[i]; 35 | 36 | if((arr[i]%2==0) && i%2==0) 37 | { 38 | even+=arr[i]; 39 | } 40 | else if((arr[i]%2!=0) && i%2!=0) 41 | { 42 | odd+=arr[i]; 43 | } 44 | } 45 | cout< 22 | char* uniqueChar(char *str){ 23 | char *ch=new char[100]; 24 | int j=0; 25 | unordered_map m; 26 | for(int i=0;str[i]!='\0';i++) 27 | { 28 | if(m.count(str[i])>0) 29 | continue; 30 | else 31 | { 32 | ch[j] = str[i]; 33 | j++; 34 | m[str[i]]=true; 35 | } 36 | 37 | } 38 | return ch; 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Find first set bit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | You are given an integer N. You need to return an integer M, in which only one bit is set which at position of lowest set bit of N (from right to left). 4 | Input Format : 5 | Integer N 6 | Output Format : 7 | Integer M 8 | Sample Input 1 : 9 | 7 10 | Sample Output 1 : 11 | 1 12 | Sample Input 2 : 13 | 12 14 | Sample Output 2 : 15 | 4 16 | 17 | 18 | CODE: 19 | */ 20 | 21 | 22 | int returnFirstSetBit(int n){ 23 | /* Don't write main(). 24 | * Don't read input, it is passed as function argument. 25 | * Return output and don't print it. 26 | * Taking input and printing output is handled automatically. 27 | */ 28 | 29 | for(int i=0;i<32;i++){ 30 | if((n&(1< 29 | 30 | using namespace std; 31 | int power(int x, int n){ 32 | if (n==0) 33 | { 34 | return 1; 35 | } 36 | 37 | return x*power(x, n-1); 38 | 39 | 40 | } 41 | 42 | int main( int argc , char ** argv ) 43 | { 44 | ios_base::sync_with_stdio(false) ; 45 | cin.tie(NULL) ; 46 | 47 | int x, n; 48 | cin>>x>>n; 49 | 50 | cout << power(x,n) << '\n'; 51 | 52 | 53 | return 0 ; 54 | } 55 | -------------------------------------------------------------------------------- /Find_the_Unique_Element.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | Given an integer array of size 2N + 1. In this given array, N numbers are present twice and one number is present only once in the array. 4 | You need to find and return that number which is unique in the array. 5 | Note : Given array will always contain odd number of elements. 6 | Input format : 7 | Line 1 : Array size i.e. 2N+1 8 | Line 2 : Array elements (separated by space) 9 | Output Format : 10 | Unique element present in the array 11 | Constraints : 12 | 1 <= N <= 10^6 13 | Sample Input : 14 | 7 15 | 2 3 1 6 3 6 2 16 | Sample Output : 17 | 1 18 | 19 | 20 | CODE: 21 | */ 22 | int ans = arr[0]; 23 | for(int i = 1; i < size; i++){ 24 | ans = ans ^ arr[i]; 25 | } 26 | return ans; 27 | -------------------------------------------------------------------------------- /First_Index_of_Number.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 3 | Given an array of length N and an integer x, you need to find and return the first index of integer x present in the array. Return -1 if it is not present in the array. 4 | First index means, the index of first occurrence of x in the input array. 5 | Do this recursively. Indexing in the array starts from 0. 6 | Input Format : 7 | Line 1 : An Integer N i.e. size of array 8 | Line 2 : N integers which are elements of the array, separated by spaces 9 | Line 3 : Integer x 10 | Output Format : 11 | first index or -1 12 | Constraints : 13 | 1 <= N <= 10^3 14 | Sample Input : 15 | 4 16 | 9 8 10 8 17 | 8 18 | Sample Output : 19 | 1 20 | 21 | CODE: 22 | */ 23 | int firstIndex(int input[], int size, int x) { 24 | for(int i=0;i 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Last_Index_of_Number.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 3 | Given an array of length N and an integer x, you need to find and return the last index of integer x present in the array. Return -1 if it is not present in the array. 4 | Last index means - if x is present multiple times in the array, return the index at which x comes last in the array. 5 | You should start traversing your array from 0, not from (N - 1). 6 | Do this recursively. Indexing in the array starts from 0. 7 | Input Format : 8 | Line 1 : An Integer N i.e. size of array 9 | Line 2 : N integers which are elements of the array, separated by spaces 10 | Line 3 : Integer x 11 | Output Format : 12 | last index or -1 13 | Constraints : 14 | 1 <= N <= 10^3 15 | Sample Input : 16 | 4 17 | 9 8 10 8 18 | 8 19 | Sample Output : 20 | 3 21 | CODE: 22 | */ 23 | 24 | int lastIndex(int input[], int size, int x) { 25 | int index=0; 26 | for(int i=0;i 42 | #include 43 | #include 44 | #include 45 | using namespace std; 46 | 47 | vector longestConsecutiveIncreasingSequence(int *arr, int n){ 48 | //Your Code goes here 49 | unordered_map countMap; 50 | vector results; 51 | 52 | for(int i=0;i 23 | using namespace std; 24 | int main() 25 | { 26 | int a=0,s=0,p=0; 27 | int n=0; 28 | cin>>n; 29 | char * str = new char [n]; 30 | cin>>str; 31 | for(int i=0;i 27 | 28 | using namespace std; 29 | 30 | int board[11][11]; 31 | 32 | bool isPossible(int n,int row,int col){ 33 | 34 | // Same Column 35 | for(int i=row-1;i>=0;i--){ 36 | if(board[i][col] == 1){ 37 | return false; 38 | } 39 | } 40 | //Upper Left Diagonal 41 | for(int i=row-1,j=col-1;i>=0 && j>=0 ; i--,j--){ 42 | if(board[i][j] ==1){ 43 | return false; 44 | } 45 | } 46 | 47 | // Upper Right Diagonal 48 | 49 | for(int i=row-1,j=col+1;i>=0 && j0) 17 | { 18 | ct++; 19 | count(n/10); 20 | } 21 | else 22 | { 23 | return ct; 24 | } 25 | } 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Pair sum to 0.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | Given a random integer array A of size N. Find and print the pair of elements in the array which sum to 0. 5 | Array A can contain duplicate elements. 6 | While printing a pair, print the smaller element first. 7 | That is, if a valid pair is (6, -6) print "-6 6". There is no constraint that out of 5 pairs which have to be printed in 1st line. You can print pairs in any order, just be careful about the order of elements in a pair. 8 | Input format : 9 | Line 1 : Integer N (Array size) 10 | Line 2 : Array elements (separated by space) 11 | Output format : 12 | Line 1 : Pair 1 elements (separated by space) 13 | Line 2 : Pair 2 elements (separated by space) 14 | Line 3 : and so on 15 | Constraints : 16 | 1 <= N <= 10^6 17 | Ai contains all non-zero values 18 | Sample Input: 19 | 5 20 | 2 1 -2 2 3 21 | Sample Output : 22 | -2 2 23 | -2 2 24 | 25 | 26 | CODE: 27 | 28 | */ 29 | 30 | #include 31 | using namespace std; 32 | 33 | void PairSum(int *input, int n){ 34 | /* Don't write main(). 35 | * the input array is already passed as function argument. 36 | * Don't need to return anything. Print the desired pairs in the function itself. 37 | */ 38 | map um; 39 | for(int i = 0;i :: iterator it; 44 | for(it = um.begin();it!=um.end();it++){ 45 | if((*it).first>0) 46 | if((*it).second>0){ 47 | if(um[0-(*it).first]){ 48 | for(int i = 0;i<((*it).second * um[0-(*it).first]);i++){ 49 | cout<<0-(*it).first<<" "<<(*it).first< 26 | using namespace std; 27 | int main() { 28 | int n; 29 | cin>>n; 30 | int arr[10000],max_profit=0; 31 | 32 | for(int i=0;i>arr[i]; 35 | 36 | for(int j=0;jmax_profit) 39 | { 40 | max_profit=arr[i]-arr[j]; 41 | } 42 | 43 | } 44 | } 45 | 46 | cout< 52 | using namespace std; 53 | int main() { 54 | 55 | // Write your code here 56 | int n; 57 | cin >> n ; 58 | int arr[n]; 59 | for(int i = 0 ; i < n ;i++){ 60 | cin >> arr[i]; 61 | } 62 | int min=arr[0],maxprofit=0; 63 | for(int i = 1 ; i < n ;i++){ 64 | if(min>arr[i]){ 65 | min = arr[i]; 66 | }else{ 67 | if(arr[i]-min >maxprofit){ 68 | maxprofit =arr[i]-min; 69 | }} 70 | } 71 | 72 | cout << maxprofit< 26 | using namespace std; 27 | int main() 28 | { 29 | int n; 30 | cin>>n; 31 | int div,mod; 32 | int ar[n]; 33 | for(int i=0;i>ar[i]; 36 | } 37 | int sum1=0,sum2=0; 38 | for(int i=0;i 22 | using namespace std; 23 | int main() 24 | { 25 | int n=0; 26 | cin>>n; 27 | int** array= new int*[n]; 28 | for(int i=0;i> array[i][j]; 34 | } 35 | 36 | } 37 | int sum=0; 38 | for(int i=0;i 32 | #include 33 | using namespace std; 34 | int FLAG=0; 35 | int main() { 36 | int nummarbles=0,target=0; 37 | cin>>nummarbles>>target; 38 | int numberstorage[100],end=0,start=0,sum=0; 39 | 40 | for(int i=0;i>numberstorage[i]; 43 | } 44 | 45 | for(int i=0;itarget) 59 | { 60 | break; 61 | } 62 | 63 | } 64 | if(FLAG==1){break;} 65 | } 66 | if(FLAG==0) 67 | { 68 | cout<<"false"; 69 | } 70 | else if(FLAG==1) 71 | { 72 | cout<<"true"< 4 | using namespace std; 5 | 6 | int main(){ 7 | int p = 5; 8 | int const *q = &p; 9 | } 10 | Options 11 | p++; 12 | q++; 13 | (*q)++; 14 | 15 | 16 | (*q)++; 17 | -------------------------------------------------------------------------------- /Quiz/Constants2: -------------------------------------------------------------------------------- 1 | 2 | Which statement(s) will give an error for the following code - 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int p = 5; 8 | int * const q = &p; 9 | } 10 | 11 | Options 12 | p++; 13 | q++; 14 | (*q)++; 15 | 16 | 17 | q++; 18 | -------------------------------------------------------------------------------- /Quiz/Constants3: -------------------------------------------------------------------------------- 1 | 2 | Which statement(s) will give an error for the following code - 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int p = 5; 8 | int const * const q = &p; 9 | } 10 | Options 11 | p++; 12 | (*q)++; 13 | q++; 14 | 15 | q++; 16 | (*q)++; 17 | -------------------------------------------------------------------------------- /Quiz/Constants4: -------------------------------------------------------------------------------- 1 | Which statement(s) will give an error for the following code - 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | const int p = 5; 7 | int const *q = &p; 8 | } 9 | Options 10 | p++; 11 | q++ 12 | (*q)++; 13 | 14 | 15 | p++; 16 | (*q)++; 17 | -------------------------------------------------------------------------------- /Quiz/Create_Array: -------------------------------------------------------------------------------- 1 | Correct statement for creating an integer array of size 5, dynamically - 2 | 3 | Options 4 | int *arr[] = new int[5]; 5 | int *arr = new int[5]; 6 | int arr = new int[5]; 7 | int *arr[5] = new int; 8 | 9 | 10 | int *arr = new int[5]; 11 | -------------------------------------------------------------------------------- /Quiz/Create_array2: -------------------------------------------------------------------------------- 1 | Correct statement for creating an integer array of size 5, dynamically - 2 | 3 | Options 4 | int *arr[] = new int[5]; 5 | int *arr = new int[5]; 6 | int arr = new int[5]; 7 | int *arr[5] = new int; 8 | 9 | 10 | int *arr = new int[5]; 11 | -------------------------------------------------------------------------------- /Quiz/Deallocate_memory: -------------------------------------------------------------------------------- 1 | How will you free the memory allocated by following program - 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int *a = new int; 7 | } 8 | 9 | 10 | delete a; 11 | -------------------------------------------------------------------------------- /Quiz/Deallocate_memory2: -------------------------------------------------------------------------------- 1 | How will you free the memory allocated by following program - 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int *a = new int; 7 | } 8 | 9 | Options 10 | free a; 11 | delete *a; 12 | delete a; 13 | new a; 14 | 15 | 16 | delete a; 17 | -------------------------------------------------------------------------------- /Quiz/Default_arguments: -------------------------------------------------------------------------------- 1 | Which of the following statement is correct? 2 | Options 3 | Only one parameter of a function can be a default parameter. 4 | Minimum one parameter of a function must be a default parameter. 5 | All the parameters of a function can be default parameters. 6 | No parameter of a function can be default. 7 | 8 | 9 | All the parameters of a function can be default parameters. 10 | -------------------------------------------------------------------------------- /Quiz/Delete_2D_array: -------------------------------------------------------------------------------- 1 | Given the following CPP Program. Select the CORRECT Syntax of deleting this 2D array? Check all that apply. 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int **twoDArray = new int*[10]; 8 | for(int i = 0; i < 10; i++) 9 | *(twoDArray + i) = new int[10]; 10 | } 11 | 12 | Options are - 13 | A. 14 | delete twoDArray [][]; 15 | 16 | B. 17 | for(int i = 0; i < 10; i++) 18 | delete twoDArray[i]; 19 | 20 | C. 21 | for(int i = 0; i < 10; i++) 22 | delete [] twoDArray[i]; 23 | 24 | D. 25 | for(int i = 0; i < 10; i++) 26 | delete twoDArray[i][]; 27 | 28 | C 29 | -------------------------------------------------------------------------------- /Quiz/Delete_array: -------------------------------------------------------------------------------- 1 | Correct statement for deallocating the array is - 2 | Options 3 | delete [] arr; 4 | delete arr; 5 | delete *arr; 6 | delete [] *arr; 7 | 8 | 9 | delete [] arr; 10 | -------------------------------------------------------------------------------- /Quiz/Delete_memory: -------------------------------------------------------------------------------- 1 | On deleting a dynamic memory, if the pointer value is not modified, then the pointer points to? 2 | 3 | Options 4 | NULL 5 | Other dynamically allocated memory 6 | The same deleted memory location 7 | It points back to location it was initialized with 8 | 9 | 10 | 11 | The same deleted memory location 12 | -------------------------------------------------------------------------------- /Quiz/Dynamic_Memory_allocation: -------------------------------------------------------------------------------- 1 | In CPP, dynamic memory allocation is done using ______________ operator. 2 | 3 | Options 4 | calloc() 5 | malloc() 6 | allocate 7 | new 8 | 9 | 10 | new 11 | -------------------------------------------------------------------------------- /Quiz/Dynamic_Memory_allocation2: -------------------------------------------------------------------------------- 1 | In CPP, dynamic memory allocation is done using ______________ operator. 2 | -------------------------------------------------------------------------------- /Quiz/Dynamic_Memory_allocation3: -------------------------------------------------------------------------------- 1 | In CPP, dynamic memory allocation is done using ______________ operator. 2 | Options 3 | calloc() 4 | malloc() 5 | allocate 6 | new 7 | 8 | 9 | new 10 | -------------------------------------------------------------------------------- /Quiz/Efficiency of an Algorithm: -------------------------------------------------------------------------------- 1 | Two main measures for the efficiency of an algorithm are - 2 | Options 3 | Processor and memory 4 | Complexity and capacity 5 | Time and space 6 | Data and space 7 | 8 | 9 | Time and space 10 | -------------------------------------------------------------------------------- /Quiz/Fibonacci: -------------------------------------------------------------------------------- 1 | What is the time complexity of following code for calculating nth fibonacci number 2 | long fib(int n){ 3 | if(n == 0 || n == 1){ 4 | return n; 5 | } 6 | return fib(n - 1) + fib(n - 2); 7 | } 8 | 9 | Options 10 | O(n) 11 | O(n^2) 12 | O(2^n) 13 | O(n^3) 14 | 15 | 16 | O(2^n) 17 | -------------------------------------------------------------------------------- /Quiz/Fibonacci2: -------------------------------------------------------------------------------- 1 | The space complexity for finding nth fibonacci number using recursion is : 2 | 3 | Options 4 | O(n) 5 | O(2^n) 6 | O(log n) 7 | O(n^2) 8 | O(nlogn) 9 | 10 | 11 | O(n) 12 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output: -------------------------------------------------------------------------------- 1 | Assume memory address of variable ‘a’ is : 400 (and an integer takes 4 bytes), what will be the output - 2 | int a = 7; 3 | int *c = &a; 4 | c = c + 3; 5 | cout << c << endl; 6 | 7 | Answer 8 | 412 9 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output2: -------------------------------------------------------------------------------- 1 | Assume memory address of variable ‘a’ is : 200 and a double variable is of size 8 bytes, what will be the output - 2 | double a = 10.54; 3 | double *d = &a; 4 | d = d + 1; 5 | cout << d << endl; 6 | Answer 7 | 208 8 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output3: -------------------------------------------------------------------------------- 1 | int a[] = {1, 2, 3, 4}; 2 | cout << *(a) << " " << *(a+1); 3 | 4 | 1 2 5 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output4: -------------------------------------------------------------------------------- 1 | Assume that address of 0th index of array ‘a’ is : 200. 2 | What is the output - 3 | int a[6] = {1, 2, 3}; 4 | cout << a << “ “ << &a; 5 | 6 | Options 7 | Error 8 | 200 204 9 | 200 200 10 | 1 200 11 | 200 1 12 | 13 | 200 200 14 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output5: -------------------------------------------------------------------------------- 1 | Assume that address of 0th index of array ‘a’ is : 200. What is the output - 2 | int a[6] = {1, 2, 3}; 3 | cout << (a + 2); 4 | 5 | Answer 6 | 208 7 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output6: -------------------------------------------------------------------------------- 1 | char s[]= "hello"; 2 | char *p = s; 3 | cout << s[0] << " " << p[0]; 4 | Answer: 5 | h h 6 | 7 | 8 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output7: -------------------------------------------------------------------------------- 1 | void fun(int a[]) { 2 | cout << a[0] << " "; 3 | } 4 | 5 | int main() { 6 | int a[] = {1, 2, 3, 4}; 7 | fun(a + 1); 8 | cout << a[0]; 9 | } 10 | 11 | Answer 12 | 13 | 2 1 14 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output8: -------------------------------------------------------------------------------- 1 | 2 | What is the output of the following program? 3 | #include 4 | using namespace std; 5 | 6 | #define MULTIPLY(a, b) a*b 7 | 8 | int main(){ 9 | cout << MULTIPLY(2+3, 3+5); 10 | return 0; 11 | } 12 | 13 | 16 14 | -------------------------------------------------------------------------------- /Quiz/Fill_the_output9: -------------------------------------------------------------------------------- 1 | What is the output of the following program? 2 | #include 3 | using namespace std; 4 | 5 | #define SQUARE(x) x*x 6 | 7 | int main(){ 8 | int x = 36 / SQUARE(6); 9 | cout << x; 10 | 11 | return 0; 12 | } 13 | 14 | 15 | 36 16 | -------------------------------------------------------------------------------- /Quiz/Inline_functions: -------------------------------------------------------------------------------- 1 | Inline functions are useful when ______ 2 | Options 3 | Function is large with many nested loops 4 | Function has many static variables 5 | Function is small and we want to avoid function call overhead. 6 | None of the above 7 | 8 | 9 | Function is small and we want to avoid function call overhead. 10 | -------------------------------------------------------------------------------- /Quiz/InsertionSort Worst Case Time Complexity: -------------------------------------------------------------------------------- 1 | Worst case time complexity of insertion sort is ? 2 | Options 3 | O(n) 4 | O(n^2) 5 | O(nlogn) 6 | O(logn) 7 | 8 | 9 | O(n^2) 10 | -------------------------------------------------------------------------------- /Quiz/Jagged_array: -------------------------------------------------------------------------------- 1 | Can we create Jagged Arrays in C++ ? 2 | Yes 3 | -------------------------------------------------------------------------------- /Quiz/Linear Search: -------------------------------------------------------------------------------- 1 | The worst case time complexity of Linear search is : 2 | Options 3 | O(n) 4 | O(n^2) 5 | O(nlogn) 6 | O(logn) 7 | 8 | O(n) 9 | -------------------------------------------------------------------------------- /Quiz/Linear Search Worst Case: -------------------------------------------------------------------------------- 1 | The Worst case(s) occur in linear search algorithm when - 2 | Options 3 | Item is somewhere in the middle of the array 4 | Item is the last element in the array 5 | Item is present at first index of the array. 6 | Item is not in the array at all 7 | 8 | 9 | Item is the last element in the array 10 | Item is not in the array at all 11 | -------------------------------------------------------------------------------- /Quiz/Merge Sort space: -------------------------------------------------------------------------------- 1 | The space complexity for merge sort is : 2 | Options 3 | O(n) 4 | O(n^2) 5 | O(nlogn) 6 | O(log n) 7 | 8 | 9 | O(n) 10 | -------------------------------------------------------------------------------- /Quiz/Merge sort: -------------------------------------------------------------------------------- 1 | What is the time complexity of merge sort : 2 | Options 3 | O(n) 4 | O(n^2) 5 | O(nlogn) 6 | O(log n) 7 | 8 | 9 | O(nlogn) 10 | -------------------------------------------------------------------------------- /Quiz/Operations for merging: -------------------------------------------------------------------------------- 1 | For merging two sorted arrays of size m and n into a sorted array of size m+n, we require operations - 2 | Options 3 | O(m * n) 4 | O(m + n) 5 | O(m) if m >= n 6 | O(n) if n > m 7 | 8 | 9 | O(m + n) 10 | -------------------------------------------------------------------------------- /Quiz/Pointer_Declaration: -------------------------------------------------------------------------------- 1 | Which of the following is the proper declaration of a pointer? 2 | Options 3 | int x; 4 | int &x; 5 | int *x; 6 | ptr x; 7 | 8 | 9 | int *x; 10 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output: -------------------------------------------------------------------------------- 1 | What will happen in this code? 2 | int a = 100, b = 200; 3 | int *p = &a, *q = &b; 4 | p = q; 5 | Options 6 | b is assigned to a 7 | p now points to b 8 | a is assigned to b 9 | q now points to a 10 | 11 | p now points to b 12 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output2: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | int a = 7; 3 | int b = 17; 4 | int *c = &b; 5 | a = *c; 6 | *c = *c + 1; 7 | cout << a << " " << b << endl; 8 | 9 | Options 10 | 18 18 11 | 7 18 12 | 17 17 13 | 17 18 14 | 15 | 17 18 16 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output3: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | float f = 10.5; 3 | float p = 2.5; 4 | float* ptr = &f; 5 | (*ptr)++; 6 | *ptr = p; 7 | cout << *ptr << “ “ << f << “ “ << p; 8 | Options 9 | 2.5 10.5 2.5 10 | 2.5 11.5 2.5 11 | 2.5 2.5 2.5 12 | 11.5 11.5 2.5 13 | 14 | 15 | 2.5 2.5 2.5 16 | 17 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output4: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | char ch = 'a'; 3 | char* ptr = &ch; 4 | ch++; 5 | cout << *ptr << endl; 6 | 7 | Options 8 | a 9 | b 10 | 97 11 | 98 12 | 13 | b 14 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output5: -------------------------------------------------------------------------------- 1 | Figure out the correct output of the following code. 2 | void changeSign(int *p){ 3 | *p = (*p) * -1; 4 | } 5 | 6 | int main(){ 7 | int a = 10; 8 | changeSign(&a); 9 | cout << a << endl; 10 | } 11 | 12 | Options 13 | -10 14 | 10 15 | Error 16 | None of the above 17 | 18 | 19 | -10 20 | 21 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output6: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | void square(int *p){ 3 | int a = 10; 4 | p = &a; 5 | *p = (*p) * (*p); 6 | } 7 | 8 | int main(){ 9 | int a = 10; 10 | square(&a); 11 | cout << a << endl; 12 | } 13 | 14 | Options 15 | 100 16 | 10 17 | Error 18 | None of these 19 | 20 | 10 21 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output7: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | int a = 100; 3 | int *p = &a; 4 | int **q = &p; 5 | int b = (**q)++; 6 | int *r = *q; 7 | (*r)++; 8 | cout << a << " " << b << endl; 9 | 10 | Options 11 | 102 100 12 | 101 100 13 | 101 101 14 | 102 101 15 | 16 | 17 | 102 100 18 | -------------------------------------------------------------------------------- /Quiz/Pointers_Output8: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | void increment(int **p){ 3 | (**p)++; 4 | } 5 | 6 | int main(){ 7 | int num = 10; 8 | int *ptr = # 9 | increment(&ptr); 10 | cout << num << endl; 11 | } 12 | 13 | Options 14 | 10 15 | 11 16 | Error 17 | None of these 18 | 19 | 20 | 11 21 | -------------------------------------------------------------------------------- /Quiz/Predict The Output: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int x = 2; 6 | x = x << 1; 7 | cout << x; 8 | } 9 | 10 | 11 | 4 12 | -------------------------------------------------------------------------------- /Quiz/Predict The Output2: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int x = -2; 6 | x = x >> 1; 7 | cout << x; 8 | } 9 | 10 | 11 | -1 12 | -------------------------------------------------------------------------------- /Quiz/Predict The Output3: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | if(~0 == 1) { 6 | cout << "yes"; 7 | } 8 | else { 9 | cout << "no"; 10 | } 11 | } 12 | 13 | 14 | Options 15 | yes 16 | no 17 | Compile time error 18 | Undefined 19 | 20 | 21 | no 22 | -------------------------------------------------------------------------------- /Quiz/Predict The Output4: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int y = 0; 6 | if(1 | (y = 1)) { 7 | cout << "y is " << y; 8 | } 9 | else { 10 | cout << y; 11 | } 12 | } 13 | 14 | 15 | Options 16 | y is 0 17 | y is 1 18 | 1 19 | 0 20 | 21 | 22 | y is 1 23 | -------------------------------------------------------------------------------- /Quiz/Predict The Output5: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int y = 1; 6 | if(y & (y = 2)) { 7 | cout << "true"; 8 | } 9 | else { 10 | cout << "false"; 11 | } 12 | } 13 | 14 | 15 | true 16 | -------------------------------------------------------------------------------- /Quiz/Recurrence for Merge Sort: -------------------------------------------------------------------------------- 1 | What is the recurrence relation for merge sort : 2 | Options 3 | T(n) = 2T(n/2) 4 | T(n) = 2T(n/2) + k 5 | T(n) = 2T(n/2) + O(n) 6 | T(n) = 2T(n/2) + O(log n) 7 | 8 | 9 | T(n) = 2T(n/2) + O(n) 10 | -------------------------------------------------------------------------------- /Quiz/Reference_variable: -------------------------------------------------------------------------------- 1 | What is the correct syntax of declaring and defining a reference? 2 | Options 3 | int a = 10; int &b; b = a; 4 | int a = 10; int &b = a; 5 | int a = 10; int b = &a; 6 | int a = 10; int &b = &a; 7 | 8 | 9 | 10 | int a = 10; int &b = a; 11 | -------------------------------------------------------------------------------- /Quiz/Selection Sort: -------------------------------------------------------------------------------- 1 | Worst case time complexity of Selection sort is ? 2 | Options 3 | O(n) 4 | O(n^2) 5 | O(nlogn) 6 | O(logn) 7 | 8 | 9 | O(n^2) 10 | -------------------------------------------------------------------------------- /Quiz/Theoretical Analysis: -------------------------------------------------------------------------------- 1 | In theoretical analysis the time factor when determining the efficiency of algorithm is measured by 2 | Options 3 | Counting microseconds 4 | Counting the number of statements in code 5 | Counting the number of unit operations 6 | Counting the kilobytes of algorithm 7 | 8 | 9 | Counting the number of unit operations 10 | -------------------------------------------------------------------------------- /Quiz/Time Complexity: -------------------------------------------------------------------------------- 1 | If the number of primary operations of an algorithm that takes an array of size n as input are 3n^2 + 5n. The worst case time complexity of the algorithm will be ? 2 | 3 | Options 4 | O(n^3) 5 | O((n^2)*logn) 6 | O(n^2) 7 | O(n) 8 | 9 | 10 | O(n^2) 11 | -------------------------------------------------------------------------------- /Quiz/Time Complexity of Code: -------------------------------------------------------------------------------- 1 | What will be the Time Complexity of following code in terms of ‘n’ ? 2 | Refer the code for C++ - 3 | for(int i = 0; i < n; i++){ 4 | for(; i < n; i++){ 5 | cout << i << endl; 6 | } 7 | } 8 | Refer the same code in Java - 9 | for(int i = 0; i < n; i++){ 10 | for(; i < n; i++){ 11 | System.out.println(i); 12 | } 13 | } 14 | Refer the same code in Python - 15 | for i in range(n): 16 | while i 2 | using namespace std; 3 | 4 | void func(int i, int& j, int p){ 5 | i++; 6 | j++; 7 | p++; 8 | } 9 | 10 | int main(){ 11 | int i = 10; 12 | int j = 6; 13 | int &p = i; 14 | func(i, j, p); 15 | cout << i << " " << j << " " << p; 16 | } 17 | 18 | Anaswer 19 | 20 | 10 7 10 21 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output11: -------------------------------------------------------------------------------- 1 | What is the output of the following program? 2 | #include 3 | using namespace std; 4 | 5 | int x = 1; 6 | 7 | void print(){ 8 | int x = 2; 9 | { 10 | int x = 3; 11 | cout << x << endl; 12 | } 13 | } 14 | int main(){ 15 | print(); 16 | return 0; 17 | } 18 | 19 | Options 20 | 1 21 | 2 22 | 3 23 | Error 24 | 25 | 26 | 27 | 3 28 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output12: -------------------------------------------------------------------------------- 1 | 2 | What is the output of the following program ? 3 | #include 4 | using namespace std; 5 | 6 | int getValue(int x = 0, int y = 0, int z){ 7 | return (x + y + z); 8 | } 9 | 10 | int main(){ 11 | cout << getValue(10); 12 | return 0; 13 | } 14 | 15 | 16 | Options 17 | 10 18 | 0 19 | 20 20 | Compilation Error 21 | 22 | 23 | 24 | Compilation Error 25 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output13: -------------------------------------------------------------------------------- 1 | 2 | What is the output of the following program ? 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int const p = 5; 8 | cout << ++p; 9 | return 0; 10 | } 11 | Options 12 | 5 13 | 6 14 | Error 15 | Garbage 16 | 17 | 18 | 19 | Error 20 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output14: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int p = 5; 7 | int const *q = &p; 8 | p++; 9 | cout << p << endl; 10 | return 0; 11 | } 12 | Options 13 | Error 14 | 5 15 | 6 16 | None 17 | 18 | 19 | 20 | 6 21 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output15: -------------------------------------------------------------------------------- 1 | 2 | What will be the output of the following code ? 3 | #include 4 | using namespace std; 5 | 6 | int func(int num){ 7 | return func(num- 1); 8 | } 9 | 10 | int main() { 11 | int num = 5; 12 | int ans = func(num - 1); 13 | cout << ans; 14 | } 15 | Options 16 | Compilation Error 17 | Runtime Error 18 | 5 19 | None of these 20 | 21 | 22 | Compilation error 23 | segmentation fault 24 | Solution Description 25 | Since the base case is missing in the code, therefore there will be infinite recursion calls and hence runtime error will occur. 26 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output16: -------------------------------------------------------------------------------- 1 | What will be the output ? 2 | #include 3 | using namespace std; 4 | 5 | void print(int n){ 6 | if(n < 0){ 7 | return; 8 | } 9 | cout << n << " "; 10 | print(n - 2); 11 | } 12 | 13 | int main() { 14 | int num = 5; 15 | print(num); 16 | } 17 | Options 18 | Runtime error 19 | 5 4 3 2 1 20 | 5 3 1 21 | None of these 22 | 23 | 24 | 5 3 1 25 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output17: -------------------------------------------------------------------------------- 1 | 2 | What will be the output of the following code ? 3 | #include 4 | using namespace std; 5 | 6 | void print(int n){ 7 | if(n < 0){ 8 | return; 9 | } 10 | if(n == 0){ 11 | cout << n << “ “; 12 | return; 13 | } 14 | print(n --); 15 | cout << n << “ “; 16 | } 17 | 18 | int main() { 19 | int num = 3; 20 | print(num); 21 | } 22 | 23 | 24 | Options 25 | Runtime Error 26 | 3 2 1 27 | 3 3 3 28 | 0 1 2 3 29 | 30 | 31 | runtime error 32 | Solution Description 33 | In function print when recursion call is being made n-- is being passed as input. Here we are using post decrement operator, so argument passed to next function call is n and not n - 1. Thus there will be infinite recursion calls and runtime error will come. 34 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output2: -------------------------------------------------------------------------------- 1 | Assume address of 0th index of array 'a' is 200. 2 | What is the output - 3 | int a[6] = {1, 2, 3}; 4 | int *b = a; 5 | cout << b[2]; 6 | Options 7 | Error 8 | 3 9 | 1 10 | 200 11 | 212 12 | 13 | 3 14 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output3: -------------------------------------------------------------------------------- 1 | Assume address of 0th index of array 'a' is 200. 2 | What is the output - 3 | int a[] = {1, 2, 3, 4, 5}; 4 | cout << *(a) << " " << *(a + 4); 5 | 6 | Options 7 | Error 8 | 200 216 9 | 1 5 10 | None of these 11 | 12 | 1 5 13 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output4: -------------------------------------------------------------------------------- 1 | int a[] = {1, 2, 3, 4}; 2 | int *p = a++; 3 | cout << *p << endl; 4 | Options 5 | 1 6 | 2 7 | Garbage value 8 | Error 9 | 10 | Error 11 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output5: -------------------------------------------------------------------------------- 1 | Assume address of 0th index of array ‘b’ is 200. What is the output - 2 | char b[] = "xyz"; 3 | char *c = &b[0]; 4 | cout << c << endl; 5 | 6 | Options 7 | 200 8 | x 9 | xyz 10 | None of these 11 | 12 | xyz 13 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output6: -------------------------------------------------------------------------------- 1 | Assume address of 0th index of array ‘b’ is 200. What is the output - 2 | char b[] = "xyz"; 3 | char *c = &b[0]; 4 | c++; 5 | cout << c << endl; 6 | 7 | Options 8 | 201 9 | y 10 | xyz 11 | yz 12 | 13 | 14 | yz 15 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output7: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int d = 65; 4 | int i = d; 5 | char ch = i; 6 | cout << ch << endl; 7 | } 8 | A 9 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output8: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | void updateValue(int *p){ 6 | *p = 610 % 255; 7 | } 8 | 9 | int main(){ 10 | char ch = 'A'; 11 | updateValue((int*)&ch); 12 | cout << ch; 13 | } 14 | 15 | 16 | d 17 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output9: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void func(int p){ 5 | cout << p << " "; 6 | } 7 | 8 | int main(){ 9 | int i = 10; 10 | int &p = i; 11 | func(p++); 12 | cout << i; 13 | } 14 | 15 | 16 | 10 11 17 | -------------------------------------------------------------------------------- /Quiz/What_is_the_output?: -------------------------------------------------------------------------------- 1 | Assume integer takes 4 bytes and integer pointer 8 bytes. 2 | int a[5]; 3 | int *c; 4 | cout << sizeof(a) << “ “ << sizeof(c); 5 | Options 6 | 8 8 7 | 5 8 8 | 20 8 9 | 20 4 10 | 11 | 12 | 20 8 13 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?: -------------------------------------------------------------------------------- 1 | int a = 7; 2 | int b = 17; 3 | int *c = &b; 4 | *c = 7; 5 | cout << a << " “ << b << endl; 6 | Options 7 | 7 17 8 | 17 7 9 | 7 7 10 | 17 17 11 | 12 | 13 | 14 | 7 7 15 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?2: -------------------------------------------------------------------------------- 1 | int a = 50; 2 | int *ptr = &a; 3 | int *q = ptr; 4 | (*q)++; 5 | cout << a << endl; 6 | 7 | Options 8 | 50 9 | 51 10 | Error 11 | None of these 12 | 13 | 14 | 51 15 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?3: -------------------------------------------------------------------------------- 1 | int a = 50; 2 | int *ptr = &a; 3 | cout << (*ptr)++ << “ “; 4 | cout << a << endl; 5 | Options 6 | 50 51 7 | 51 50 8 | 51 51 9 | 50 50 10 | 11 | 50 51 12 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?4: -------------------------------------------------------------------------------- 1 | int *ptr = 0; 2 | int a = 10; 3 | *ptr = a; 4 | cout << *ptr << endl; 5 | Options 6 | 10 7 | 0 8 | Error 9 | None of these 10 | 11 | Error 12 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?5: -------------------------------------------------------------------------------- 1 | int a = 7; 2 | int *c = &a; 3 | c = c + 1; 4 | cout << a << " " << *c << endl; 5 | Options 6 | Garbage_value 7 7 | 7 Garbage_value 8 | 8 8 9 | 7 7 10 | 11 | 12 | 7 Garbage_value 13 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?6: -------------------------------------------------------------------------------- 1 | int a = 10; 2 | int *p = &a; 3 | int **q = &p; 4 | int b = 20; 5 | *q = &b; 6 | (*p)++; 7 | cout << a << " " << b << endl; 8 | 9 | Options 10 | 10 21 11 | 11 20 12 | 11 21 13 | 10 20 14 | 15 | 10 21 16 | -------------------------------------------------------------------------------- /Quiz/What_will_be_the_output?7: -------------------------------------------------------------------------------- 1 | int a = 100; 2 | int *p = &a; 3 | int **q = &p; 4 | int b = (**q)++ + 4; 5 | cout << a << " " << b << endl; 6 | 7 | Options 8 | 100 104 9 | 101 104 10 | 101 105 11 | 100 105 12 | 13 | 14 | 101 104 15 | -------------------------------------------------------------------------------- /Quiz/void_pointer: -------------------------------------------------------------------------------- 1 | Void pointer can point to which type of objects ? 2 | Options 3 | int 4 | double 5 | float 6 | All 7 | 8 | 9 | all 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codezen 2 | ![](https://classroom.codingninjas.in/assets-app/images/CNLOGO.svg) 3 | The repository is a part of the project [Competitive Programming](https://github.com/users/Aman9026/projects/3) and contains the solutions of all the problems I attempted in practice or competitions on [Codezen](https://codezen.codingninjas.com/dashboard) which would be definetly very helpful if you do competitive programming. 4 | 5 | ***You are always welcome to add more or optimize any solution in this repository by following [these](https://github.com/Aman9026/Codezen/blob/master/CONTRIBUTING.md) instructions.*** 6 | 7 | -------------------------------------------------------------------------------- /Rat In A Maze Problem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | 5 | You are given a N*N maze with a rat placed at maze[0][0]. Find and print all paths that rat can follow to reach its destination i.e. maze[N-1][N-1]. Rat can move in any direc­tion ( left, right, up and down). 6 | Value of every cell in the maze can either be 0 or 1. Cells with value 0 are blocked means rat can­not enter into those cells and those with value 1 are open. 7 | Input Format 8 | Line 1 : Integer N 9 | Next N Lines : Each line will contain ith row elements (separated by space) 10 | Output Format : 11 | One Line for every possible solution. 12 | Every line will have N*N maze elements printed row wise and are separated by space. Only cells that are part of solution path should be 1, rest all cells should be 0. 13 | Sample Input 1 : 14 | 3 15 | 1 0 1 16 | 1 0 1 17 | 1 1 1 18 | Sample Output 1 : 19 | 1 0 0 1 0 0 1 1 1 20 | Sample Output 1 Explanation : 21 | Only 1 path is possible 22 | Sample Input 2 : 23 | 3 24 | 1 0 1 25 | 1 1 1 26 | 1 1 1 27 | Sample Output 2 : 28 | 1 0 0 1 1 1 1 1 1 29 | 1 0 0 1 0 0 1 1 1 30 | 1 0 0 1 1 0 0 1 1 31 | 1 0 0 1 1 1 0 0 1 32 | Sample Output 2 Explanation : 33 | 4 paths are possible 34 | 35 | 36 | 37 | 38 | 39 | 40 | CODE: 41 | */ 42 | 43 | #include 44 | using namespace std; 45 | int board[20][20] = {0}; 46 | 47 | void ratMaze(int maze[][20], int n, int row, int col){ 48 | if(row == n-1 && col == n-1){ 49 | for(int i = 0; i< n; i++){ 50 | for(int j = 0; j= 0 && col >= 1 && row=1 && col >=0 && row [0, 1, 3, 2] -> [0, 1, 2, 3] 25 | In second T.C., [2, 1, 0] -> [1, 2, 0] OR [2, 1, 0] -> [2, 0, 1] So, it is impossible to sort. 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | CODE: 34 | */ 35 | 36 | #include 37 | 38 | using namespace std; 39 | 40 | bool skillSort(vector &skills, int start, int end){ 41 | // cout << start<<" " <= end) 43 | { 44 | return 1; 45 | } 46 | 47 | int n = skills.size(); 48 | int mid = (start+end)/2; 49 | 50 | int left = skillSort(skills, start, mid); 51 | int right = skillSort(skills, mid+1, end); 52 | 53 | if (left!=1 || right != 1) 54 | { 55 | return 0; 56 | } 57 | 58 | if (skills[mid+1]>skills[mid]) 59 | { 60 | return 1; 61 | } 62 | 63 | // cout << "mid "<1) 67 | { 68 | return 0; 69 | } 70 | 71 | if (skills[mid+1]>t; 88 | 89 | while(t--){ 90 | int n; 91 | cin>>n; 92 | //cout << "n "< skills; 95 | for (int i = 0; i < n; ++i) 96 | { 97 | int temp; 98 | cin>>temp; 99 | skills.push_back(temp); 100 | } 101 | 102 | if (skillSort(skills, 0, n-1)==1) 103 | { 104 | cout << "Yes" << '\n'; 105 | }else{ 106 | cout << "No" << '\n'; 107 | } 108 | 109 | } 110 | 111 | 112 | 113 | return 0 ; 114 | } 115 | -------------------------------------------------------------------------------- /Sudoku Solver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | Given a 9*9 sudoku board, in which some entries are filled and others are 0 (0 indicates that the cell is empty), you need to find out whether the Sudoku puzzle can be solved or not i.e. return true or false. 5 | Input Format : 6 | 9 Lines where ith line contains ith row elements separated by space 7 | Output Format : 8 | true or false 9 | Sample Input : 10 | 9 0 0 0 2 0 7 5 0 11 | 6 0 0 0 5 0 0 4 0 12 | 0 2 0 4 0 0 0 1 0 13 | 2 0 8 0 0 0 0 0 0 14 | 0 7 0 5 0 9 0 6 0 15 | 0 0 0 0 0 0 4 0 1 16 | 0 1 0 0 0 5 0 8 0 17 | 0 9 0 0 7 0 0 0 4 18 | 0 8 2 0 4 0 0 0 6 19 | Sample Output : 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | CODE: 29 | */ 30 | 31 | 32 | bool FindUnassignedLocation(int grid[9][9], int &row, int &col); 33 | bool isSafe(int grid[9][9], int row, int col, int num); 34 | 35 | 36 | bool sudokuSolver(int grid[][9]){ 37 | int row,col; 38 | if(!FindUnassignedLocation(grid,row,col)){ 39 | return true; 40 | } 41 | for(int num=1;num<=9;num++){ 42 | if(isSafe(grid,row,col,num)){ 43 | grid[row][col] = num; 44 | if(sudokuSolver(grid)){ 45 | return true; 46 | } 47 | else { 48 | grid[row][col]=0; 49 | } 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | bool FindUnassignedLocation(int grid[9][9], int &row, int &col){ 56 | for(row=0;row<9;row++){ 57 | for(col=0;col<9;col++){ 58 | if(grid[row][col]==0){ 59 | return true; 60 | } 61 | } 62 | } 63 | return false; 64 | } 65 | 66 | bool UsedInRow(int grid[9][9], int row, int num) 67 | { 68 | for (int col = 0; col < 9; col++) 69 | if (grid[row][col] == num) 70 | return true; 71 | return false; 72 | } 73 | 74 | bool UsedInCol(int grid[9][9], int col, int num) 75 | { 76 | for (int row = 0; row < 9; row++) 77 | if (grid[row][col] == num) 78 | return true; 79 | return false; 80 | } 81 | 82 | bool UsedInBox(int grid[9][9], int boxStartRow, int boxStartCol, int num) 83 | { 84 | for (int row = 0; row < 3; row++) 85 | for (int col = 0; col < 3; col++) 86 | if (grid[row+boxStartRow][col+boxStartCol] == num) 87 | return true; 88 | return false; 89 | } 90 | 91 | bool isSafe(int grid[9][9], int row, int col, int num) 92 | { 93 | return !UsedInRow(grid, row, num) && !UsedInCol(grid, col, num) && 94 | !UsedInBox(grid, row - row % 3 , col - col % 3, num); 95 | } 96 | -------------------------------------------------------------------------------- /Sum me Up.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PROBLEM: 3 | 4 | There will be ‘t’ test cases having an integer. You have to sum up all the digits of this integer. For e.g. For 6754, the answer will be 6 + 7 + 5 + 4 = 22. 5 | Input Format: 6 | First line will have an integer ‘t’ denoting the number of test cases. 7 | Next ‘t’ lines will have an integer ‘val’ each. 8 | Output format: 9 | Print ‘t’ lines of output denoting the sum of all the digits of the number in each test case. 10 | Constraints: 11 | 1 <= t <= 10^5 12 | 0 <= val <= 10^18 13 | Sample Input: 14 | 2 15 | 1547 16 | 45876 17 | Sample Output: 18 | 17 19 | 30 20 | Explanation: 21 | 1 + 5 + 4 + 7 = 17 22 | 4 + 5 + 8 + 7 + 6 = 30 23 | 24 | 25 | CODE: 26 | 27 | */ 28 | 29 | 30 | #include 31 | using namespace std; 32 | typedef unsigned long long ull; 33 | int main() { 34 | 35 | ull t; 36 | cin>>t; 37 | while(t--){ 38 | ull val; 39 | cin>>val; 40 | ull s = 0; 41 | while(val!=0){ 42 | s+=val%10; 43 | val/=10; 44 | } 45 | cout< 29 | 30 | using namespace std; 31 | 32 | class student{ 33 | public: 34 | string name; 35 | int marks; 36 | int roll; 37 | }; 38 | 39 | bool mycompare(student a, student b){ 40 | 41 | if (a.marks!=b.marks) 42 | { 43 | return (a.marks>b.marks); 44 | }else{ 45 | return(a.roll>n; 58 | 59 | //std::vector name; //ncross1 60 | std::vector stud; //ncross3 61 | 62 | for (int i = 0; i < n; ++i) 63 | { 64 | string temp_name; 65 | int sub1; 66 | int sub2; 67 | int sub3; 68 | cin>>temp_name>>sub1>>sub2>>sub3; 69 | 70 | int sum = sub1+sub2+sub3; 71 | 72 | student temp_sub; 73 | 74 | temp_sub.name = temp_name; 75 | temp_sub.marks = sum; 76 | temp_sub. roll = i+1; 77 | 78 | stud.push_back(temp_sub); 79 | } 80 | sort(stud.begin(), stud.end(), mycompare); 81 | 82 | for (int i = 0; i < n; ++i) 83 | { 84 | cout << i+1<<" "<arr[j]){ 44 | int temp = arr[i]; 45 | arr[i] = arr[j]; 46 | arr[j] = temp; 47 | } 48 | } 49 | } 50 | 51 | for(int i = 0;i 29 | using namespace std; 30 | 31 | struct interval{ 32 | long st; 33 | long et; 34 | }; 35 | 36 | int main() { 37 | long t; 38 | cin>>t; 39 | long counter = 0; 40 | interval ar[t]; 41 | for(long i = 0;i>ar[i].st; 43 | } 44 | for(long i = 0;i>ar[i].et; 46 | } 47 | long max = 0; 48 | for(long i = 0;i<2400;i++){ 49 | for(long j = 0;j