├── .github └── ISSUE_TEMPLATE │ ├── add-a-question.md │ ├── add-a-topic-subtopic.md │ ├── ask-a-query.md │ └── suggest-an-idea.md ├── Arrays ├── 1D Arrays │ ├── All or any │ │ └── All_or_any.cpp │ ├── Count_inversion │ │ ├── Question.txt │ │ └── Solution.cpp │ ├── Welcome.txt │ └── maxsubbarraysum.cpp └── 2D Arrays │ ├── LongestIncreasingPath.cpp │ ├── MatrixRotation_90_clockwise.cpp │ ├── Welcome.txt │ ├── setmatrixaszero.cpp │ ├── sortAndPrintBoundaryElementsOf2dArray.java │ └── spirallyTraversingAMatrix.cpp ├── Basic Codes ├── Operation_Choice.cpp ├── Welcome.txt ├── average.cpp ├── bubble_sort.cpp ├── digit_names.cpp ├── factorial_1.cpp ├── positive_negative.cpp ├── prime_range_upto_50.cpp ├── reverse.cpp ├── roots_of_quad_Eq.cpp ├── swap.cpp └── swap_1.cpp ├── Bit Manipulation └── Welcome.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CodeChef ├── ATM.cpp ├── Chef Zomo and Zoo.cpp ├── Chef and his bookstore.cpp ├── CuriousMatrix.cpp ├── Longest AND Subarray.cpp ├── Mahasena.cpp ├── Maximise the Subsequence Sum.cpp ├── Movie Weekend │ ├── Question.txt │ ├── Solution.cpp │ └── readme.md ├── PROBDIFF.cpp ├── PrimeGame.cpp ├── SHUFFLIN.cpp ├── Welcome.txt ├── XOR_Equal.cpp ├── alicevsbobfaceoff.cpp ├── chefWars.cpp ├── lapindrome.cpp └── polynomial_root.cpp ├── CodeForces ├── A_Array_with_Odd_Sum.cpp ├── A_Beautiful_Matrix.cpp ├── Array_Optimization_by_Deque.cpp ├── Boats_Competition.cpp ├── D. Productive Meeting.cpp ├── Deep_Down_Below.cpp ├── Hacking_Cypher.cpp.cpp ├── Higher_Order_Functions.cpp ├── Jury_Meeting.cpp ├── K-th Not Divisible by n ├── K-th Not Divisible by n.cpp ├── Less or Equal.cpp ├── Maximum Light Up.cpp ├── Nastia and Nearly Good Numbers.cpp ├── Non-zero_Segments.cpp ├── Non_Decreasing_Dilemma.cpp ├── Permutation_Minimization.cpp ├── Registration_system.cpp ├── Shifting_Sort.cpp ├── Similar_Pairs.cpp ├── Sum_of_Cubes ├── Ternary String.cpp ├── Turn_the_Rectangles.cpp ├── Welcome.txt └── Yet_Another_Palindromic_Problem.cpp ├── CodersArena ├── Coders Arena.md └── coders arena logo.png ├── Coding Competition ├── Consistency-1.cpp └── Xs_and_Os.cpp ├── Data Structure ├── Graph │ ├── Directed Graph │ │ └── Welcome.txt │ └── Undirected Graph │ │ └── Welcome.txt ├── Heap │ ├── Find k’th largest element in an array.cpp │ ├── Implementation-using-vector.cpp │ └── Welcome.txt ├── Linked List │ ├── Circular Linked List │ │ └── Welcome.txt │ ├── Doubly Linked List │ │ └── Welcome.txt │ └── Single Linked List │ │ ├── DetectLoopInSinglyLinkedList.cpp │ │ ├── Welcome.txt │ │ └── reverseKNodes.cpp ├── Queue │ ├── Basic Queue │ │ └── Welcome.txt │ ├── Circular Queue │ │ └── Welcome.txt │ └── Priority Queue │ │ └── Welcome.txt ├── Stack │ ├── Balanced parenthesis.cpp │ ├── Next_Greater_Element.cpp │ ├── Questions.txt │ ├── Stack Using Linked List.cpp │ ├── Stack using array.cpp │ ├── dynamic_stacks_using_array_and_template.cpp │ └── kstack in a array.cpp └── Trees │ ├── AVL Trees │ └── Welcome.txt │ ├── B+ Trees │ └── Welcome.txt │ ├── Binary Trees │ ├── Diameter_of_Tree.cpp │ ├── Height_of_Tree.cpp │ ├── LeftViewOfBinaryTree.cpp │ ├── Levelorder.cpp │ ├── No_of_Nodes.cpp │ ├── SumReplacement.cpp │ ├── Sum_of_Nodes.cpp │ ├── Verticalorder.cpp │ ├── Welcome.txt │ └── sumatk.cpp │ └── Red Black Trees │ └── Welcome.txt ├── Datatype-String └── string.txt ├── Datatype-double └── double.txt ├── Datatype-int └── int.txt ├── Documentation ├── Create char.txt ├── Installing IDE- Eclipse for C++ │ ├── Steps to install Eclipse for C++.txt │ ├── img1.png │ ├── img10.png │ ├── img11.png │ ├── img2.png │ ├── img3.png │ ├── img4.png │ ├── img5.png │ ├── img6.png │ ├── img7.png │ ├── img8.png │ └── img9.png ├── Installing IDE-CodeBlocks_c++ │ ├── Steps to install CodeBlocks for C++.txt │ ├── img (1).png │ ├── img (14).png │ ├── img (15).png │ ├── img (2).png │ ├── img (3).png │ ├── img (4).png │ ├── img (5).png │ ├── img (6).png │ ├── img (7).png │ └── img (9).png ├── Installing IDE-Dev C++ │ ├── Agreement.png │ ├── Download.png │ ├── Hello.png │ ├── Installation_Guide.txt │ ├── components.png │ ├── file.png │ ├── finish.png │ ├── fonts.png │ ├── installing.png │ ├── language.png │ ├── location.png │ ├── output.png │ ├── select_lang.png │ └── success.png ├── Installing IDE-Turbo_C++ │ ├── 1.PNG │ ├── 10.png │ ├── 11.png │ ├── 2.PNG │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ ├── 9.png │ └── StepsToInstall.txt ├── Installing IDE-VScode │ ├── Check.png │ ├── Installation_completion.png │ ├── Installer_Vscode.png │ ├── Installer_mingw.png │ ├── SYstemSetting.jfif │ ├── SourceForge.jfif │ ├── Steps to install Vscode For C++.docx │ ├── StepsToinstall.txt │ ├── SystemProperties.png │ ├── apply.png │ ├── bin.png │ ├── env_variables.png │ ├── env_variables2.png │ ├── ex1.png │ ├── ex2.png │ ├── ex3.png │ ├── extensions.png │ ├── min.png │ ├── mingw.png │ ├── mingw2.png │ ├── mingw3.png │ ├── mingwPath.png │ ├── path.png │ ├── requirements.png │ └── vscode.png ├── Installing Sublime in Linux │ ├── Installation Guide for C++.txt │ ├── apt setup.png │ ├── build.png │ ├── gpg key.png │ ├── installing.png │ ├── key add success.png │ ├── output.png │ ├── stable.png │ └── terminal.png ├── Intro To C++.md ├── Math - sinh() , cosh() , tanh() ├── String - push_back(), pop_back() │ ├── pop_back.txt │ └── push_back.txt ├── Strings_getline │ └── String_Getline().txt ├── Template_HTML_Reference.html ├── Template_TXT_Reference.md ├── images │ ├── cpp.png │ ├── logo.png │ ├── question.png │ └── write.png ├── intro.html └── write.png ├── Dynamic Programming ├── 0-1-KnapsackDP.cpp ├── Editdistance.cpp ├── Eggdrop.cpp ├── Longestpalindromicsequuence.cpp ├── Prisoners_escape │ └── images │ │ ├── Escape.cpp │ │ └── escape_cpp.png ├── Stock Buy Sell to Maximize Profit.cpp ├── Welcome.txt └── knapsack.cpp ├── Exception Handling └── Welcome.txt ├── File Handling └── Welcome.txt ├── Functions-capacity,resize,shrink_to_fit └── functions.txt ├── Game Theory └── Welcome.txt ├── GeeksForGeeks ├── Cuttingrod.cpp ├── Huffman_Coding_For_Data_Compression.cpp ├── Job-Sequencing-Problem.cpp ├── Kadane's Algorithm │ ├── README.md │ └── main.cpp ├── MatrixChainMultiplicationDP.cpp ├── Median_in_sorted_rowwise_matrix │ ├── Question.md │ └── Solution.cpp ├── Median_sorted_array_diff_size │ ├── Question.md │ └── solution-tausiq.cpp ├── Minimum-Platform.cpp ├── Subarray_with_zero_sum.cpp ├── doublylinkiedlist.c ├── knap_sack.cpp ├── kth-element-2sorted-arrays.cpp ├── maxincsum.cpp ├── odd-after-even-LinkedList.cpp ├── reverse array.cpp ├── reverselinkedlistusingrec.cpp └── spiraltraversal.cpp ├── Greedy Algorithms ├── GreedyAlgorithm.txt ├── Question-1_team.cpp ├── Question-2_HelpfulMaths.cpp ├── question-3_choosingTeams.cpp ├── question-4_FairElection.cpp ├── question-5_GreedyPuppy.cpp └── question-6_GiftsFixing.cpp ├── Hackerearth └── Welcome.txt ├── Hackerrank ├── Basic Data Types.cpp ├── Birthday_Cake_Candles.cpp ├── Day of the Programmer │ ├── Question.txt │ ├── README.md │ └── Solution.cpp ├── For Loop │ └── For Loop.cpp ├── Hotel Prices │ └── Hotel Prices.cpp ├── Magic Spells │ └── Magic Spells.cpp ├── Maximum HourGlass Sum 2D Array.cpp ├── Variable-sized-arrays │ ├── question.md │ └── solution.cpp └── Welcome.txt ├── Interview Questions └── Welcome.txt ├── Interviewbit └── SubstringConcatenation.cpp ├── LICENSE ├── LeetCode ├── Dungeon Game │ ├── Question.txt │ ├── Screen Shot 2021-10-02 at 10.09.01 PM.png │ ├── Solution.cpp │ └── readme.md ├── 3Sum │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Check If It Is a Straight Line.cpp ├── Climbing Stairs.cpp ├── Delete Duplicate folders.cpp ├── Find All Duplicates in an Array │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Find the Highest Altitude │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Fizz Buzz.cpp ├── GenerateParentheses │ ├── generateparentheses.cpp │ └── ques.txt ├── Gray Code.cpp ├── House Robber │ ├── README.md │ ├── question.txt │ └── solution.cpp ├── Interger To Roman │ ├── Question.txt │ ├── Solution.cpp │ └── readme.md ├── Island perimeter │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Jump Game II │ ├── Question.txt │ ├── readme.md │ └── solution.cpp ├── Jump Game │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Letter Combinations of a Phone Number │ ├── README.md │ ├── question.md │ └── solution.cpp ├── Merge k Sorted Lists │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── MiddleLL.cpp ├── Permutation.cpp ├── Power-of-four │ ├── Readme.md │ └── Solution.cpp ├── Remove Outermost Paranthesis │ ├── question.txt │ ├── readme.md │ └── solution.cpp ├── Repeated DNA Sequences │ ├── README.md │ ├── question.txt │ └── solution.cpp ├── ReverseInteger │ ├── ques.txt │ └── reverseInteger.cpp ├── Search Insert Position.cpp ├── Smallest String With A Given Numeric Value │ ├── README.md │ ├── question.txt │ └── solution.cpp ├── Sorting Ascending.cpp ├── Subtract the Product and Sum of Digits of an Integer.cpp ├── Welcome.txt ├── ZigZagConversion │ ├── ques.txt │ └── zigzag.cpp ├── reverseKNodes.cpp ├── spirallyTraversingAMatrix.cpp └── trappingRainWater.cpp ├── Number Theory └── Special_Number.cpp ├── OOPs └── Welcome.txt ├── Pattern printing ├── Basic_pattern_1.cpp ├── Letter J.cpp ├── Letter W.cpp ├── Letter_A.cpp ├── Letter_B.cpp ├── Letter_C.cpp ├── Letter_E.cpp ├── Letter_F.cpp ├── Letter_H.cpp ├── Letter_I.cpp ├── Letter_K.cpp ├── Letter_L.cpp ├── Letter_M.cpp ├── Letter_N.cpp ├── Letter_V.cpp ├── Letter_X.cpp ├── Letter_Y.cpp ├── Letter_Z.cpp ├── butterfly Pattern.cpp └── welcome.txt ├── Questions.xlsx ├── README.md ├── Recursion ├── GCD-HCF.cpp ├── Pascaltriangle.cpp ├── Welcome.txt └── factorial.cpp ├── SECURITY.md ├── Searching └── Welcome.txt ├── Sorting ├── Bubble_Sort.cpp ├── Insertion_sort.cpp ├── Merge Sort.cpp ├── Merge_sort.cpp ├── Selection_sort.cpp ├── SemiSort_2.cpp ├── Semisort_1.cpp └── Welcome.txt ├── String Handling ├── Date validation.cpp ├── Longestcommonsequenec.cpp ├── Longestincreasingsubseq.cpp ├── Welcome.txt ├── ZippedString.cpp └── rotating digits and max number.cpp ├── Theory Questions and Answers └── Welcome.txt ├── index.html ├── logo.png ├── pull_request_template.md └── website_name.txt /.github/ISSUE_TEMPLATE/add-a-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Add a question 3 | about: Purpose your own question 4 | title: "[Question Title]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Enter your question - 11 | Your answer 12 | 13 | ### Enter link to the question(if question belongs to any online platform) - 14 | Your answer 15 | 16 | ### Tags for the question(eg - Array, Basic, Stack, etc.) - 17 | Your answer 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/add-a-topic-subtopic.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Add a topic/subtopic 3 | about: Purpose a topic/sub-topic to add in Documentation 4 | title: "[Topic -> Subtopics you wish to work upon]" 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Enter topic you want to work upon(eg- String, Loop) - 11 | Write your answer here 12 | 13 | ### Enter sub-topic you want to work upon(eg- for loop, pow()) 14 | Write your answer here 15 | 16 | ### While claiming the issue, kindly mention your real name and document type that you will submit (**Choices available** -> .txt or .html). 17 | 18 |

19 | 20 | 21 | ### Templates for reference - [.txt](https://github.com/SarthakKeshari/CPP-Questions-and-Solutions/blob/main/Documentation/Template_TXT_Reference.md) and [.html](https://github.com/SarthakKeshari/CPP-Questions-and-Solutions/blob/main/Documentation/Template_HTML_Reference.html) 22 | #### For contributors opting for .txt are requested to visit .html too in order to get clear idea what content to write and how it will be diplayed on the webpage. 23 | 24 |
25 | 26 | By creating/claiming the issue or by creating PR(pull request) for this issue you agree to the below conditions - 27 | 28 | - [x] I affirm that my document is less than **20%** plagarised.
29 | - [x] If my document is found to be more than **20%** plagarised, my PR(pull request) can be rejected without any prior information.
30 | - [x] I give the right to maintainers/admins/collaborators of this repository/project/website to amend/add/remove my document wherever/whenever is found necessary.
31 | 32 | **For clear details you may visit - #419** 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ask-a-query.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a query 3 | about: Have a doubt? 4 | title: Query - [Query Title] 5 | labels: doubt 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Enter your query - 11 | Write your query here 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggest-an-idea.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Suggest an idea 3 | about: What more can be implemented in this repository to help students 4 | title: "[Idea Title]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### A brief about your proposal - 11 | Your answer 12 | -------------------------------------------------------------------------------- /Arrays/1D Arrays/Count_inversion/Question.txt: -------------------------------------------------------------------------------- 1 | Two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j and we have to calculate the total number of inversion in that array. 2 | -------------------------------------------------------------------------------- /Arrays/1D Arrays/Count_inversion/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //for sum of array 5 | int sum(int aa[],int x) 6 | { int s = 0; 7 | while(x > 0) 8 | {s += aa[x]; 9 | x -= x & (-x); 10 | } 11 | return s; 12 | } 13 | 14 | //change bst at a given node 15 | void change(int aa[],int n,int x,int val) 16 | { 17 | while(x<=n) 18 | {aa[x]+= val; 19 | x+=x&(-x); 20 | } 21 | } 22 | 23 | //central function to work 24 | int count(int arr[], int n) 25 | { 26 | int ic=0; 27 | 28 | int max=0; 29 | for (int i=0;i=0;i--) 38 | { 39 | ic += sum(aa,arr[i]-1); 40 | change(aa,max,arr[i],1); 41 | } 42 | 43 | return ic; 44 | } 45 | 46 | int main() 47 | { 48 | int n; 49 | cin>>n; 50 | int arr[n]; 51 | for(int i=0;i>arr[i]; 53 | } 54 | cout < 3 | #include 4 | using namespace std; 5 | //maxsubarraysum function to find max sum 6 | int maxsubarraysum(int arr[],int n) 7 | { 8 | int max_sum=0; //initialize max_sum 9 | int curr_sum=INT_MIN; //initialize curr_sum=INT_MIN to overcome negative values. 10 | for(int i=0;imax_sum) 14 | { 15 | max_sum=curr_sum; 16 | } 17 | if(curr_sum<0) 18 | { 19 | curr_sum=0; 20 | } 21 | } 22 | return max_sum; 23 | } 24 | 25 | //Driver program to test maxsubarraysum 26 | int main() 27 | { 28 | cout<<"Enter the number of Elements"<>n; 31 | cout<<"Enter the elements in array"<>arr[i]; 36 | } 37 | int maximumsum=maxsubarraysum(arr,n); 38 | cout<<"Maximum contiguous sum of array is "< 4 | using namespace std; 5 | 6 | #define N 4 7 | 8 | // Function to rotate the matrix 90 degree clockwise 9 | void rotate90Clockwise(int a[N][N]) 10 | { 11 | 12 | // Traverse each cycle 13 | for (int i = 0; i < N / 2; i++) { 14 | for (int j = i; j < N - i - 1; j++) { 15 | 16 | // Swap elements of each cycle 17 | // in clockwise direction 18 | int temp = a[i][j]; 19 | a[i][j] = a[N - 1 - j][i]; 20 | a[N - 1 - j][i] = a[N - 1 - i][N - 1 - j]; 21 | a[N - 1 - i][N - 1 - j] = a[j][N - 1 - i]; 22 | a[j][N - 1 - i] = temp; 23 | } 24 | } 25 | } 26 | 27 | // Function to Display Matrix 28 | void printMatrix(int arr[N][N]) 29 | { 30 | for (int i = 0; i < N; i++) { 31 | for (int j = 0; j < N; j++) 32 | cout << arr[i][j] << " "; 33 | cout << '\n'; 34 | } 35 | } 36 | 37 | 38 | int main() 39 | { 40 | int arr[N][N] = { { 2, 10, 5, 3}, 41 | { 7, 8, 9, 11}, 42 | { 14, 15, 16, 13 }, 43 | { 1, 4, 6, 10 } }; 44 | cout<<"Matrix Before Rotation"< 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | //Showing the menu for the user 10 | cout<<"Options are:-"<>a>>b; 25 | 26 | int ch; 27 | 28 | cout<<"\nEnter you choice\n"; 29 | cin>>ch; 30 | //Performing operations and printing the output based on user choice. 31 | if(ch == 1){ 32 | cout<<"Additon of two no's is:- "<<(a+b); 33 | 34 | 35 | 36 | } 37 | 38 | 39 | else if(ch == 2){ 40 | 41 | cout<<"subtraction of two no's is:- "<<(a-b); 42 | 43 | } 44 | 45 | 46 | else if(ch == 3){ 47 | 48 | cout<<"multiplication of two no's is:- "<<(a*b); 49 | 50 | } 51 | 52 | 53 | 54 | else if(ch == 4){ 55 | if (b == 0){ 56 | cout<<"Division by 0 not allowed"; 57 | } 58 | else{ 59 | 60 | cout<<"multiplication of two no's is:- "<<(a*b); 61 | } 62 | } 63 | else{ 64 | 65 | cout<<"Invalid Choice"; 66 | } 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Basic Codes/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Basic Codes/Welcome.txt -------------------------------------------------------------------------------- /Basic Codes/average.cpp: -------------------------------------------------------------------------------- 1 | // write the program for calculation average of 10 marks 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int arr []={1,3,5,7,9,5,2,9,9,2}; //taken 10 marks of students 9 | int sum=0; 10 | 11 | for(int i=0;i<10;i++) // traversing the array 12 | { 13 | sum=sum+arr[i] ; 14 | } 15 | double average = sum/10.0; 16 | 17 | cout<<"Average: "< 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a = 1; 9 | if(a == 1) 10 | { 11 | cout << "one"; 12 | 13 | } 14 | else if(a == 2) 15 | { 16 | cout << "two"; 17 | } 18 | else if(a == 3) 19 | { 20 | cout << "three"; 21 | } 22 | else if(a == 4) 23 | { 24 | cout << "four"; 25 | } 26 | else if(a == 5) 27 | { 28 | cout << "five"; 29 | } 30 | else if(a == 6) 31 | { 32 | cout << "six"; 33 | } 34 | else if(a == 7) 35 | { 36 | cout << "seven"; 37 | } 38 | else if(a == 8) 39 | { 40 | cout << "eight"; 41 | } 42 | else if(a == 9) 43 | { 44 | cout << "nine"; 45 | } 46 | else if(a == 0) 47 | { 48 | cout << "zero"; 49 | } 50 | else 51 | { 52 | cout << "invalid input"; 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Basic Codes/factorial_1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file factorial_1.cpp 3 | * @author BodaleDenis (denisbodale.work@gmail.com) 4 | * @brief This program implements factorial of a number N (using loop) 5 | * @date 2021-09-29 6 | */ 7 | 8 | // Write a program to find factorial of a number entered by the user. (Using loop) 9 | #include 10 | 11 | int factorial(int number) 12 | { 13 | int product = 1, iter; // Product should be initialised by 1 since 0 would produce 0 outcome on final result 14 | if(number < 0) 15 | { 16 | std::cout << "Impossible, factorial is available only for positive numbers"; 17 | } 18 | else if(number == 0) 19 | { 20 | return 1; // 0! is equal to 1 21 | } 22 | else 23 | { 24 | for(iter = 1; iter <= number; iter++) 25 | { 26 | product = product * iter; 27 | } 28 | } 29 | return product; 30 | 31 | } 32 | 33 | // Driver code 34 | 35 | int main() 36 | { 37 | int number; 38 | std::cout << "Choose the number to calculate factorial:" << "\n"; 39 | std::cin >> number; 40 | std::cout << "Factorial of " << number <<" is " << factorial(number) << "\n"; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Basic Codes/positive_negative.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int N; 8 | cin>>N; 9 | if (N<0) 10 | 11 | cout << "Negative" << endl; 12 | else 13 | cout << "Positive" << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Basic Codes/prime_range_upto_50.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | cout<<"Prime nos from 1 to 50 are : \n"; 7 | 8 | for (int i=2;i<=50;i++) 9 | { 10 | int c=0; 11 | for (int a=2 ; a<=sqrt(i);++a) 12 | { 13 | if (i%a==0) 14 | c=1; 15 | } 16 | if (c==0) 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int arr[100], i, n; 6 | cout<<"Enter No. of Elements: "; 7 | cin>>n 8 | cout<<"Enter Array Elements: "; 9 | for(i=0; i>arr[i]; 11 | cout<<"\n\nThe Reverse of Given Array is:\n"; 12 | for(i=(n-1); i>=0; i--) 13 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | float a,b,c,D,X1,X2,img,real; 9 | char ch=253; 10 | cout<<"please enter the coefficients of x"<>a>>b>>c; 12 | D=b*b-4*a*c; 13 | 14 | if(D>0) 15 | { 16 | X1=(-b+sqrt(D))/(2*a); 17 | X2=(-b-sqrt(D))/(2*a); 18 | cout<<"The roots are Real and Different."< 3 | using namespace std; 4 | int main() { 5 | 6 | // Assume x = 32, y = 35 belongs to Natural number. 7 | 8 | int x = 32, y = 35; 9 | 10 | cout<<"Before swapping" <>a>>b; 11 | 12 | cout<<"the numbers before the swapping are:"< 17 | using namespace std; 18 | 19 | int main(){ 20 | 21 | int withdraw; 22 | double balance; 23 | cin >> withdraw >> balance; 24 | 25 | if (withdraw % 5 == 0 && withdraw + 0.5 <= balance) 26 | { 27 | cout << balance - withdraw - 0.5 << endl; 28 | } 29 | else 30 | { 31 | cout << balance; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /CodeChef/Chef and his bookstore.cpp: -------------------------------------------------------------------------------- 1 | 2 | // question link :- https://www.codechef.com/CDSP2021/problems/SEPT202/ 3 | 4 | #include 5 | #define N 100005 6 | #define mod 1000000007 7 | #define INF 2147483647 8 | #define ll long long 9 | #define ln "\n" 10 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 11 | using namespace std; 12 | int main() 13 | { 14 | 15 | fast(); 16 | // n is the input taking from the user 17 | ll n; 18 | cin>>n; 19 | 20 | // we have declared an array of size n 21 | ll array[n]; 22 | for(ll i=0;i>array[i]; 26 | } 27 | 28 | /* Here we have take three parameters, the beginning of the 29 | array , the length n upto which we want the array to 30 | be sorted and to demonstrate descending order sort have used greater<>().*/ 31 | sort(array,array+n,greater<>()); 32 | 33 | 34 | // initially initialized to zero 35 | ll count = 0; 36 | 37 | for(ll i=0;i Fury-MadMax) 51 | -------------------------------------------------------------------------------- /CodeChef/Longest AND Subarray.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Codechef - Longest AND Subarray question 5 | 6 | Link to the question- 7 | 8 | https://www.codechef.com/OCT21C/problems/ANDSUBAR 9 | 10 | 11 | */ 12 | 13 | #include 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | // your code goes here 19 | long long int t, n, i, p, temp, ans; 20 | cin >> t; 21 | while (t--) 22 | { 23 | cin >> n; 24 | // Initialize the value of temp 25 | temp = 1; 26 | 27 | // Find the maximum value of temp for which (2*temp) should be less than equal to n. 28 | while ((temp * 2) <= n) 29 | { 30 | temp = temp * 2; 31 | } 32 | p = temp / 2; 33 | 34 | // store the range of longest subarray in variable name ans 35 | ans = max(n - temp + 1, temp - p); 36 | 37 | // Print ans 38 | cout << ans << "\n"; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /CodeChef/Mahasena.cpp: -------------------------------------------------------------------------------- 1 | /* Question 2 | Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason 3 | for that was their really powerful army, also called as Mahasena. 4 | 5 | Kattapa was known to be a very superstitious person. He believed that a soldier is "lucky" if the soldier is holding an even number of weapons, and "unlucky" 6 | otherwise. He considered the army as "READY FOR BATTLE" if the count of "lucky" soldiers is strictly greater than the count of "unlucky" soldiers, and "NOT READY" otherwise. 7 | 8 | Given the number of weapons each soldier is holding, your task is to determine whether the army formed by all these soldiers is "READY FOR BATTLE" or "NOT READY". 9 | https://www.codechef.com/problems/AMR15A */ 10 | 11 | /* Input 12 | The first line of input consists of a single integer N denoting the number of soldiers. The second line of input consists of N space separated integers 13 | A1, A2, ..., AN, where Ai denotes the number of weapons that the ith soldier is holding. */ 14 | 15 | /* Output 16 | Generate one line output saying "READY FOR BATTLE", if the army satisfies the conditions that Kattapa requires or "NOT READY" otherwise (quotes for clarity). */ 17 | 18 | #include 19 | using namespace std; 20 | 21 | int main() 22 | { 23 | int t; 24 | int lucky=0,unlucky=0; 25 | 26 | cin>>t; 27 | for(int i=0;i>m; 31 | if(m%2==0) 32 | lucky++; 33 | else 34 | unlucky++; 35 | 36 | 37 | } 38 | if(lucky>unlucky) 39 | cout<<"READY FOR BATTLE"; 40 | else 41 | cout<<"NOT READY"; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /CodeChef/Maximise the Subsequence Sum.cpp: -------------------------------------------------------------------------------- 1 | 2 | // question link :- https://www.codechef.com/START10C/problems/SIGNFLIP/ 3 | 4 | #include 5 | #define N 100005 6 | #define mod 1000000007 7 | #define INF 2147483647 8 | #define ll long long 9 | #define ln "\n" 10 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 11 | using namespace std; 12 | int main() 13 | { 14 | 15 | fast(); 16 | // d is the number of test cases 17 | int d; 18 | cin>>d; 19 | while(d--) 20 | { 21 | // taking the input from the user 22 | ll n,k; 23 | cin>>n>>k; 24 | 25 | // we have declared an array of size n 26 | ll array[n]; 27 | ll sum=0; 28 | for(int j=0;j>array[j]; // taking the inputs as an array inside the loop 31 | } 32 | 33 | /* Here we have take two parameters, the beginning of the 34 | array , the length n upto which we want the array to 35 | be sorted */ 36 | 37 | sort(array,array+n); 38 | 39 | 40 | for(int j=0;j0) 51 | { 52 | sum+=array[j]; // total sum 53 | } 54 | } 55 | cout< Fury-MadMax) 60 | 61 | -------------------------------------------------------------------------------- /CodeChef/Movie Weekend/Question.txt: -------------------------------------------------------------------------------- 1 | Question: 2 | 3 | Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch. 4 | 5 | There are n movies to watch during this weekend. Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. Egor wants to watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, he would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with the minimal index among them. 6 | 7 | Your task is to help Egor to pick a movie to watch during this weekend. 8 | 9 | Input 10 | The first line of the input contains an integer T denoting the number of test cases. 11 | 12 | The first line of the test case description contains an integer n. 13 | 14 | The second line of the test case description contains n integers L1, L2, ...,Ln. The following line contains n integers R1, R2, ..., Rn. 15 | 16 | Output 17 | For each test case, output a single integer i denoting the index of the movie that Egor should watch during this weekend. Note that we follow 1-based indexing. 18 | 19 | Constraints 20 | 1 ≤ T ≤ 5 21 | 1 ≤ n ≤ 100 22 | 1 ≤ Li, Ri ≤ 100 23 | Sample Input 1 24 | 2 25 | 2 26 | 1 2 27 | 2 1 28 | 4 29 | 2 1 4 1 30 | 2 4 1 4 31 | Sample Output 1 32 | 1 33 | 2 34 | 35 | 36 | -------------------------------------------------------------------------------- /CodeChef/Movie Weekend/Solution.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/MOVIEWKN 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | // test cases 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | // there are n no of movies 13 | int n; 14 | cin>>n; 15 | //where as arr and brr are two array for accepting input ie. rating and length of the movie. 16 | int arr[n],brr[n]; 17 | int product=0,rating=0,index=0; 18 | // loop for taking input ie. length of all the movies. 19 | for(int i=0;i>arr[i]; 22 | 23 | } 24 | // loop for taking input ie. reting of all the movies. 25 | for(int i=0;i>brr[i]; 28 | } 29 | // now here our main logic. ittreate a loop for n times ie. n is the no of movies. 30 | for(int i=0;i=product && brr[i] > rating ) 37 | { 38 | product=arr[i]*brr[i]; 39 | rating = brr[i]; 40 | index=i; 41 | 42 | } 43 | } 44 | cout< 6 | using namespace std; 7 | 8 | int main(){ 9 | int t; 10 | cin>>t;//inputing number of test cases 11 | if(t>=1 && t<=1000){ 12 | while(t--){ //will repeat till variable t becomes 0 13 | int a,b,c,d; //problems 14 | cin>>a>>b>>c>>d; 15 | if(a>=1 && a<=10 && b>=1 && b<=10 && c>=1 && c<=10 && d>=1 && d<=10){ //problems and their conditions 16 | if(a==b && b==c && c==d) cout<<"0\n"; 17 | else if(a==b || a==c || a==d || b==c || b==d || c==d) cout<<"1\n"; 18 | else if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d) cout<<"2\n"; 19 | } 20 | } 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /CodeChef/SHUFFLIN.cpp: -------------------------------------------------------------------------------- 1 | /*Chef is given an array A consisting of N positive integers. Chef shuffles the array A and creates a new array B of length N, where Bi=(Ai+i)mod2, for each i(1≤i≤N). 2 | Find the maximum possible sum of integers of the array B, if Chef shuffles the array A optimally. 3 | https://www.codechef.com/SEPT21B/problems/SHUFFLIN/ */ 4 | 5 | #include 6 | using namespace std; 7 | #define ll long long 8 | #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); 9 | 10 | int main(){//start of main function 11 | fast; 12 | ll t,n,e,o,ele,s; 13 | cin>>t; 14 | while(t--){ 15 | cin>>n; 16 | if(n%2!=0){ 17 | o=(n+1)/2;//calculating how many odd positions are present in the length n 18 | e=n/2;//calculating how many even positions are present in the length n 19 | } 20 | else 21 | e=o=n/2; 22 | s=0;//initialising s(sum variable) as 0 23 | for(int i=1;i<=n;i++){ 24 | cin>>ele; 25 | if(ele%2==0&&o>0){//counting for even numbers 26 | o--; 27 | s++; 28 | } 29 | else if(ele%2!=0&&e>0){//counting for odd numbers 30 | e--; 31 | s++; 32 | } 33 | else{ 34 | if(ele%2==0) 35 | e--; 36 | else 37 | o--; 38 | } 39 | } 40 | cout< 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int tc; //Number of Test Cases 10 | cin >> tc; 11 | while(tc--) 12 | { 13 | int h,p; 14 | cin >> h >> p; // h is Darth's Health and p is Chef Power 15 | while(h!=0 && p!=0) //Check till h becomes zero or p comes to zero 16 | { 17 | if(h>p) 18 | h = h-p; //decrease p from h 19 | else 20 | h=0; 21 | 22 | p/=2; //On every attack Chef's power becomes half 23 | } 24 | if(h) 25 | { 26 | 27 | cout << 0 << endl; //If p becomes zero before h did not become zero 28 | } 29 | else 30 | { 31 | cout << 1 << endl; //p is non-negative integer and h decreases to zero 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CodeChef/lapindrome.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match. 3 | Your task is simple. Given a string, you need to tell if it is a lapindrome.*/ 4 | 5 | 6 | #include 7 | using namespace std; 8 | 9 | int main() { 10 | // your code goes here 11 | 12 | //Insert number of values you want to enter 13 | int t; 14 | cin>>t; 15 | //the loop would run until t !=0 16 | while(t--){ 17 | string s; 18 | //insert a string 19 | cin>>s; 20 | int l=s.length(); 21 | //intializing the arrays a and b 22 | int a[26]={0}; 23 | int b[26]={0}; 24 | 25 | 26 | 27 | //we spilt the string into halves and compare the halves 28 | for(int i=0;i 2 | using namespace std; 3 | 4 | void solve() 5 | { 6 | int n; // n is number of test cases. 7 | 8 | cin>>n; 9 | 10 | int a[n]; // array of size n. 11 | 12 | int sum = 0; // sum variable will store sum of elements of array. 13 | for (int i = 0; i>a[i]; 17 | 18 | sum += a[i]; // this is storing sum of elements. 19 | } 20 | if (sum % 2 == 0) // if value of sum of elements of array is odd then output will be no. 21 | { 22 | cout<<"NO"<>t; 38 | 39 | while(t--) 40 | { 41 | solve(); 42 | } 43 | } -------------------------------------------------------------------------------- /CodeForces/A_Beautiful_Matrix.cpp: -------------------------------------------------------------------------------- 1 | // 263A - Beautiful Matrix 2 | // http://codeforces.com/problemset/problem/263/A 3 | // importing the libraries 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | // Defining the main Function 10 | int main() 11 | { 12 | int x = 0; // Initialising the integer X. 13 | for (int i = 1; i <= 5; ++i) 14 | { 15 | for (int j = 1; j <= 5; ++j) // Opening a 'for' loop for taking the input 16 | { 17 | cin >> x; 18 | if (x == 1) 19 | { 20 | cout << abs(i - 3) + abs(j - 3) << endl; // Here 'abs' returns the absolute value of the parameter 21 | } 22 | } 23 | } 24 | return 0; // Evidence that our code will terminate here 25 | } -------------------------------------------------------------------------------- /CodeForces/Deep_Down_Below.cpp: -------------------------------------------------------------------------------- 1 | // que link -->https://codeforces.com/problemset/problem/1561/C 2 | // SANYAM JAIN // 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #define ll long long 20 | #define lli unsigned long long 21 | #define pb push_back 22 | #define in insert 23 | #include 24 | #define cn cout << "NO\n" 25 | #define cy cout << "YES\n" 26 | #define cm cout << "-1\n" 27 | #define vv vector v 28 | #define eli else if 29 | #define el else 30 | #define nl endl 31 | #define ss set s 32 | #define MOD 1000000007 33 | #define mode 1000000009 34 | using namespace std; 35 | 36 | int main() 37 | { 38 | ll t = 1; 39 | cin >> t; 40 | while (t--) 41 | { 42 | ll n; 43 | cin >> n; // input num 44 | vector > vp; // initialing vactor vp 45 | 46 | for(ll i=1;i<=n;i++) 47 | { 48 | ll k,m=0; 49 | cin>>k; 50 | for(ll j=0;j>x; 53 | m=max(m,x-j+1); 54 | } 55 | vp.push_back({m,k}); // push back pair to vp 56 | } 57 | sort(vp.begin(),vp.end()); // to sort the array 58 | ll p=0,l=0; 59 | for(auto i:vp) 60 | { 61 | p=max(p,i.first-l); 62 | l += i.second; 63 | } 64 | cout< 3 | using namespace std; 4 | int main(){ 5 | int n,k; 6 | cin>>n>>k; 7 | //creating the array of size n 8 | int a[n]; 9 | for(int i=0;i>a[i]; 11 | } 12 | //using the sort function to sorting the array in o(nlogn) 13 | sort(a,a+n); 14 | //checking for k is equal to 0 if k is equal to 0 and first element 15 | //is equal to 1 then print -1 else 1 16 | if(k==0) 17 | cout<<(a[0]==1? -1:1); 18 | else{ 19 | //checking for same value of a[k-1] and a[k] 20 | if(a[k-1]==a[k]) cout<<-1; 21 | else cout< 5 | #define N 100005 6 | #define mod 1000000007 7 | #define INF 2147483647 8 | #define ll long long 9 | #define ln "\n" 10 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 11 | using namespace std; 12 | int main() 13 | { 14 | 15 | fast(); 16 | // d is the number of test cases 17 | ll d; 18 | cin>>d; 19 | while(d--) 20 | { 21 | ll P,a,b,c,x,y; 22 | 23 | // taking the input from the user 24 | cin>>P>>a>>b>>c>>x>>y; 25 | 26 | // total cost of anar will be the product of number of fuljharis and their cost + anar cost 27 | ll Q = x * a + b; 28 | 29 | // total cost of chakri will be the product of number of fuljharis and their cost + chakri cost 30 | ll R = y * a + c; 31 | 32 | ll solution = 0; 33 | if (Q < R) // if chakri is greater then this conditon holds 34 | { 35 | solution = Q; 36 | } 37 | else 38 | { 39 | solution = R; // if annar is greater then this condition holds 40 | } 41 | 42 | cout << P / solution < Fury-MadMax) 48 | 49 | 50 | -------------------------------------------------------------------------------- /CodeForces/Nastia and Nearly Good Numbers.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Problem Link :- https://codeforces.com/problemset/problem/1521/A 3 | 4 | #include 5 | #define N 100005 6 | #define mod 1000000007 7 | #define INF 2147483647 8 | #define ll long long 9 | #define ln "\n" 10 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 11 | using namespace std; 12 | int main() 13 | { 14 | fast(); 15 | 16 | int c; // c is the number of test cases 17 | cin>>c; 18 | while(c--) 19 | { 20 | // taking the input from the user 21 | ll A,B; 22 | cin>>A>>B; 23 | ll p,q,r; 24 | 25 | // assuming that p is a positive integer that takes a nearly good number. 26 | p=A; 27 | 28 | // for q to be a perfectly good number if it is divisible by the product A*B. 29 | q=A*B; 30 | 31 | // according to question constraint this must hold 32 | r=q+p; 33 | 34 | if(p==q) 35 | { 36 | // if it dont satisfy the conditions print NO 37 | cout<< "NO" < Fury-MadMax) 48 | -------------------------------------------------------------------------------- /CodeForces/Permutation_Minimization.cpp: -------------------------------------------------------------------------------- 1 | //C++ program to find the lexicographically smallest possible sequence of elements in the deque 2 | //after the entire permutation has been processed. 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t; 9 | //Taking input for t->number of test cases 10 | cin >> t; 11 | while (t--) 12 | { 13 | int n; 14 | //Taking input for n->permutation size 15 | cin >> n; 16 | vector v(n); 17 | 18 | //Taking inputs for elements of the permutation. 19 | for (int i = 0; i < n; i++) 20 | { 21 | cin >> v[i]; 22 | } 23 | 24 | //Creating a deque 25 | deque d; 26 | 27 | //Adding first element in the deque 28 | d.push_back(v[0]); 29 | for(int i=1;iv[i]) 32 | { 33 | d.push_front(v[i]); //Adding elements at the beginning if it smaller than the first element 34 | } 35 | else{ 36 | d.push_back(v[i]); //Adding elements at the end if it is greater than the first element 37 | } 38 | } 39 | 40 | //Printing the elements of the deque 41 | cout< Master-Helix) 2 | 3 | //question link - https://codeforces.com/contest/1490/problem/C 4 | 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 10 | #define ll long long 11 | #define l long long 12 | 13 | 14 | 15 | int main() 16 | { 17 | fast(); 18 | ll t; 19 | cin>>t; 20 | while(t--) // no. of test cases 21 | { 22 | ll n; 23 | cin>>n; // the number to be expressed as sum of cubes 24 | ll i=1; 25 | int flag=0; 26 | while(i*i*i 4 | using namespace std; 5 | // validating the window for valid numbers of 1, 2 and 3 6 | bool verify( int window[4]){ 7 | if(window[0]==0 && window[1]>=1 && window[2]>=1 && window[3]>=1 ) return true; 8 | return false; 9 | } 10 | // function f2 for the slinding window of size mid 11 | bool f2(string s, int mid){ 12 | int window[4]={0,0,0,0}; 13 | int i=0,p=0; 14 | int n=s.size(); 15 | for(;i>t; 46 | while(t--){ 47 | string s; 48 | cin>>s; 49 | cout< Master-Helix) 6 | 7 | #include 8 | using namespace std; 9 | 10 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 11 | #define ll long long 12 | #define l long long 13 | 14 | 15 | 16 | 17 | 18 | // RAKSHIT 19 | int main() 20 | { 21 | 22 | fast(); 23 | ll n; 24 | cin>>n; 25 | vector>v; // store width and height of each rectangle in form of pair inside a vector 26 | for(int i=0;i>w1>>h1; 30 | v.push_back(make_pair(w1,h1)); 31 | } 32 | 33 | ll maxi=max(v[0].first,v[0].second); // set maxi as first value of rectangle (maximum of width and height) 34 | 35 | int flag=0; 36 | for(int i=1;imaxi) 41 | { 42 | flag=1; 43 | break; 44 | } 45 | else // if min value is more than previous max , then domino is not formed so break the loop 46 | { 47 | if(val2<=maxi) 48 | { 49 | maxi=val2; 50 | } 51 | else 52 | { 53 | maxi=val; 54 | } 55 | } 56 | } 57 | 58 | if(flag==1) // to print the desired output 59 | { 60 | cout<<"NO"; 61 | } 62 | else 63 | { 64 | cout<<"YES"; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /CodeForces/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/CodeForces/Welcome.txt -------------------------------------------------------------------------------- /CodersArena/Coders Arena.md: -------------------------------------------------------------------------------- 1 | # Coders Arena 2 |
3 | 4 | ![logo](https://i.imgur.com/g9Bbo2Q.png) 5 | 6 | # Inspiration behind creating the logo 7 | 8 | I really love creating logos. When I saw the issue regarding *help for logo designing* I knew that I could be of some help to this wonderful community of Sarthak Keshari. So I designed this logo which looks like a cubical arena which symbolizes a place where like minded coders can help each other out. I'm really happy that I get to be a part of this amazing community! -------------------------------------------------------------------------------- /CodersArena/coders arena logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/CodersArena/coders arena logo.png -------------------------------------------------------------------------------- /Coding Competition/Consistency-1.cpp: -------------------------------------------------------------------------------- 1 | //https://www.facebook.com/codingcompetitions/hacker-cup/2021/qualification-round/problems/A1 2 | #include 3 | using namespace std; 4 | #define ll long long 5 | #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 6 | 7 | int main(){ 8 | fast; 9 | ll t; 10 | cin>>t; 11 | for(int p=1;p<=t;p++){ 12 | string s; 13 | cin>>s; 14 | vector v(26);//counter for individual vowel 15 | vector c(26);//counter for individual consonant 16 | ll vc=cc=0;//counter for total vowel and consonant 17 | for(int i=0;i 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | // Function to find the k'th largest element in an array using min-heap 9 | int findKthLargest(vector const &ints, int k) 10 | { 11 | // base case 12 | if (ints.size() < k) { 13 | exit(-1); 14 | } 15 | 16 | // create a min-heap using `std::priority_queue` and insert 17 | // the first `k` array elements into the heap 18 | // `std::greater` is used as the comparison function for min-heap 19 | priority_queue, greater> pq(ints.begin(), ints.begin() + k); 20 | 21 | // do for remaining array elements 22 | for (int i = k; i < ints.size(); i++) 23 | { 24 | // if the current element is more than the root of the heap 25 | if (ints[i] > pq.top()) 26 | { 27 | // replace root with the current element 28 | pq.pop(); 29 | pq.push(ints[i]); 30 | } 31 | } 32 | 33 | // return the root of min-heap 34 | return pq.top(); 35 | } 36 | 37 | int main() 38 | { 39 | vector ints = { 7, 4, 6, 3, 9, 1 }; 40 | int k = 2; 41 | 42 | cout << "k'th largest array element is " << findKthLargest(ints, k); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Data Structure/Heap/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Heap/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Linked List/Circular Linked List/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Linked List/Circular Linked List/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Linked List/Doubly Linked List/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Linked List/Doubly Linked List/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Linked List/Single Linked List/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Linked List/Single Linked List/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Queue/Basic Queue/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Queue/Basic Queue/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Queue/Circular Queue/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Queue/Circular Queue/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Queue/Priority Queue/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Queue/Priority Queue/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Stack/Next_Greater_Element.cpp: -------------------------------------------------------------------------------- 1 | // GFG Link to question - https://practice.geeksforgeeks.org/problems/next-larger-element-1587115620/1 2 | 3 | // This Code is Contributed by RAKSHIT PANDEY (Username-----> Master-Helix) 4 | 5 | 6 | // Function to print the Next Greater Element using Stack 7 | 8 | vector nextLargerElement(vector arr, int n){ 9 | 10 | vectorv; // to store the output 11 | 12 | v.push_back(-1); // for rightmost element . no right element present 13 | stacks; 14 | s.push(arr[n-1]); //rightmost at top 15 | for(int i=n-2;i>=0;i--) // iterating backwards 16 | { 17 | if(arr[i] 4 | using namespace std; 5 | 6 | struct Node { 7 | int data; 8 | Node* left; 9 | Node* right; 10 | 11 | Node(int d) 12 | { 13 | data = d; 14 | left = NULL; 15 | right = NULL; 16 | } 17 | }; 18 | 19 | // Function to calculate height of the tree 20 | 21 | int HeightOfTree(Node* root) 22 | { 23 | if (!root) 24 | return 0; 25 | 26 | int x = HeightOfTree(root->left); 27 | int y = HeightOfTree(root->right); 28 | 29 | return (max(x, y) + 1); 30 | } 31 | 32 | // Function to calculate Diameter of the tree 33 | 34 | int DiameterOfTree(Node* root) 35 | { 36 | if (!root) 37 | return 0; 38 | 39 | int lh = HeightOfTree(root->left); // Height of left subtree 40 | int rh = HeightOfTree(root->right); // Height of right subtree 41 | 42 | int Dia = lh + rh + 1; // Current diameter 43 | 44 | int ld = DiameterOfTree(root->left); // Diameter of left subtree 45 | int rd = DiameterOfTree(root->right); // Diameter of right subtree 46 | 47 | return max(Dia , max(ld, rd)); 48 | } 49 | 50 | int main() 51 | { 52 | Node* root = new Node(15); 53 | root->left = new Node(8); 54 | root->right = new Node(3); 55 | root->left->left = new Node(4); 56 | root->left->right = new Node(11); 57 | root->right->left = new Node(10); 58 | root->right->right = new Node(7); 59 | root->left->right->right = new Node(6); 60 | root->right->right->right = new Node(7); 61 | root->left->right->right->left = new Node(14); 62 | 63 | int ans = DiameterOfTree (root); 64 | 65 | cout << ans; 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /Data Structure/Trees/Binary Trees/Height_of_Tree.cpp: -------------------------------------------------------------------------------- 1 | // 3. Calculate Height of a Binary tree. 2 | 3 | #include 4 | using namespace std; 5 | 6 | struct Node { 7 | int data; 8 | Node* left; 9 | Node* right; 10 | 11 | Node(int d) 12 | { 13 | data = d; 14 | left = NULL; 15 | right = NULL; 16 | } 17 | }; 18 | 19 | // Function to calculate height of the tree 20 | 21 | int HeightOfTree(Node* root) 22 | { 23 | if (!root) 24 | return 0; 25 | 26 | int x = HeightOfTree(root->left); // Height of left subtree 27 | int y = HeightOfTree(root->right); // Height of right subtree 28 | 29 | return (max(x, y) + 1); 30 | } 31 | 32 | int main() 33 | { 34 | Node* root = new Node(15); 35 | root->left = new Node(8); 36 | root->right = new Node(3); 37 | root->left->left = new Node(4); 38 | root->left->right = new Node(11); 39 | root->right->left = new Node(10); 40 | root->right->right = new Node(7); 41 | root->left->right->right = new Node(6); 42 | root->right->right->right = new Node(7); 43 | 44 | int ans = HeightOfTree(root); 45 | 46 | cout << ans; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Data Structure/Trees/Binary Trees/No_of_Nodes.cpp: -------------------------------------------------------------------------------- 1 | // 1. Calculate number of nodes in a Binary Tree 2 | 3 | #include 4 | using namespace std; 5 | 6 | struct Node { 7 | int data; 8 | Node* left; 9 | Node* right; 10 | 11 | Node(int d) 12 | { 13 | data = d; 14 | left = NULL; 15 | right = NULL; 16 | } 17 | }; 18 | 19 | // Recursive function to count the nodes 20 | 21 | int CountNodes(Node* root) 22 | { 23 | if (!root) 24 | return 0; 25 | 26 | int a = CountNodes(root->left); // Nodes of left subtree 27 | int b = CountNodes(root->right); // Nodes of right subtree 28 | 29 | return a + b + 1; 30 | } 31 | 32 | int main() 33 | { 34 | Node* root = new Node(15); 35 | root->left = new Node(8); 36 | root->right = new Node(3); 37 | root->left->left = new Node(4); 38 | root->left->right = new Node(11); 39 | root->right->left = new Node(10); 40 | root->right->right = new Node(7); 41 | root->left->right->right = new Node(6); 42 | root->right->right->right = new Node(7); 43 | 44 | int ans = CountNodes(root); 45 | 46 | cout << ans; 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Data Structure/Trees/Binary Trees/Sum_of_Nodes.cpp: -------------------------------------------------------------------------------- 1 | // 2. Calculate the sum of nodes of a binary tree 2 | 3 | #include 4 | using namespace std; 5 | 6 | struct Node { 7 | int data; 8 | Node* left; 9 | Node* right; 10 | 11 | Node(int d) 12 | { 13 | data = d; 14 | left = NULL; 15 | right = NULL; 16 | } 17 | }; 18 | 19 | int SumOfNodes(Node* root) 20 | { 21 | if (!root) 22 | return 0; 23 | 24 | int a = SumOfNodes(root->left); // Sum of left subtree 25 | int b = SumOfNodes(root->right); // Sum of right subtree 26 | 27 | return a + b + root->data; 28 | } 29 | 30 | int main() 31 | { 32 | Node* root = new Node(15); 33 | root->left = new Node(8); 34 | root->right = new Node(3); 35 | root->left->left = new Node(4); 36 | root->left->right = new Node(11); 37 | root->right->left = new Node(10); 38 | root->right->right = new Node(7); 39 | root->left->right->right = new Node(6); 40 | root->right->right->right = new Node(7); 41 | 42 | int ans = SumOfNodes(root); 43 | 44 | cout << ans; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Data Structure/Trees/Binary Trees/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Trees/Binary Trees/Welcome.txt -------------------------------------------------------------------------------- /Data Structure/Trees/Red Black Trees/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Data Structure/Trees/Red Black Trees/Welcome.txt -------------------------------------------------------------------------------- /Datatype-String/string.txt: -------------------------------------------------------------------------------- 1 | Main Topic – Data Types 2 | Sub-topic – string 3 | 4 | Formal Definition 5 | • It is a non-primitive datatype. 6 | • It is used for storing sequence of characters enclosed within double quotes. 7 | • One must include library, header file in the source code to use strings. 8 | Easy and Clear Explanation (along with examples) 9 | string s = “Happy Birthday” 10 | Here we have taken s as a string datatype which stores Happy Birthday as sequence of characters within double quotes. 11 | Solved Questions 12 | Write a program to print a string. 13 | 14 | #include 15 | #include 16 | using namespace std; 17 | int main() 18 | { 19 | string s = “Feeling Cool”; 20 | cout << s; 21 | return 0; 22 | } 23 | 24 | Output 25 | 26 | Feeling Cool 27 | Practice Questions 28 | Write a program to check whether it is a palindrome string or not. 29 | Write a program to multiply 2 strings. 30 | 31 | -Anushka Srivastava 32 | -------------------------------------------------------------------------------- /Datatype-double/double.txt: -------------------------------------------------------------------------------- 1 | 2 | Main Topic – Data Types 3 | Sub-topic - double 4 | 5 | Formal Definition 6 | • It is a primitive datatype. 7 | • It is used to store decimal values. 8 | • The size of double is 8 bytes i.e. 64 bits. 9 | • The range of double is 1.7e-308 to 1.7e+308 10 | 11 | 12 | Easy and Clear Explanation (along with examples) 13 | Example 14 | 15 | double n = 22.3 16 | 17 | Here we have taken n as a variable of double datatype which store decimal values like 22.3 . 18 | 19 | 20 | Solved Questions(Maximum 2) 21 | 22 | Write a program to subtract to decimal numbers. 23 | #include 24 | using namespace std; 25 | int main() 26 | { 27 | double n1, n2, sub; 28 | n1 = 22.4; 29 | n2 = 12.2; 30 | sub = n1 – n2; 31 | 32 | cout<< “Subtraction of two decimal numbers : “ << sub << endl; 33 | return 0; 34 | } 35 | 36 | Output 37 | Subtraction of two decimal numbers : 10.2 38 | 39 | Write a program to add two decimal numbers. 40 | #include 41 | using namespace std; 42 | int main() 43 | { 44 | double n1,n2, sum; 45 | n1 = 3.6; 46 | n2 = 2.2 47 | sum = n1 + n2; 48 | 49 | cout<< “Sum of two decimal numbers : “ << sum << endl; 50 | return 0; 51 | } 52 | Output 53 | Sum of two decimal numbers : 5.8 54 | 55 | Practice Questions(Minimum 2) 56 | *Medium to Hard level - This line is for developers info. Kindly remove it before creating a PR 57 | Write a program to take base and height as inputs from the user and find the area of triangle. 58 | Formula – 1/2 * base * height 59 | Write a program to find the sum of the n terms of a series. 60 | 1/2 + 3/4 + 5/6 + 7/8 + 9/10 --------------- n terms 61 | -------------------------------------------------------------------------------- /Datatype-int/int.txt: -------------------------------------------------------------------------------- 1 | Main Topic – Data Types 2 | Sub-topic - int 3 | 4 | 5 | Formal Definition 6 | • It is a primitive datatype. 7 | • It stores integer values. 8 | • The size of int is 4 bytes i.e. 32 bits. 9 | • The range is -2147483648 (-2^31) to 2147483647(2^31-1). 10 | 11 | 12 | Easy and Clear Explanation (along with examples) 13 | Example 14 | Declaring a value 15 | int a = 2230 16 | Here we have taken a is a variable of int type which store integer values like 2230. 17 | 18 | Solved Questions(Maxiumum 2) 19 | 20 | Write a program to add to integer numbers. 21 | public class Solution 22 | { 23 | public static void main(String[] args) { 24 | int n1 = 10; 25 | int n2 = 20; 26 | int sum = n1+n2; 27 | System.out.println("Sum of two integer number : "+sum); 28 | } 29 | } 30 | 31 | Output 32 | Sum of two integer number : 30 33 | 34 | Write a program to multiply two integer numbers. 35 | public class Solution 36 | { 37 | public static void main(String[] args) { 38 | int n1 = 2; 39 | int n2 = 3; 40 | int mul = n1*n2; 41 | System.out.println("Multiplication of two integer numbers : "+mul); 42 | } 43 | } 44 | 45 | Output 46 | Multiplication of two integer numbers : 6 47 | 48 | Practice Questions(Minimum 2) 49 | *Medium to Hard level - This line is for developers info. Kindly remove it before creating a PR 50 | • Write a program to check whether a number is a Palindrome number or not? 51 | A palindromic number is a number that remains the same when its digits are reversed. 52 | E.g. 121 53 | • Write a program to check whether a number is a Armstrong number or not? 54 | Armstrong number is a number that is equal to the sum of cubes of its digits. 55 | E.g. 153 56 | 57 | -Anushka Srivastava 58 | -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/Steps to install Eclipse for C++.txt: -------------------------------------------------------------------------------- 1 | Steps to install Eclipse for C++ 2 | ---------------------------------------------------------------------------------------------------- 3 | 4 | 5 | Pre-requisites: 6 | -system with processor intel i3 or ryzen 3 and above 7 | -ram: 4gb and above 8 | -internet connectivity to download eclipse and some packages 9 | ---------------------------------------------------------------------------------------------------------------------- 10 | step 1: Download ans Install Mingw (https://sourceforge.net/projects/mingw/) 11 | Eclipse CDT uses C/C++ Compiler. Hence before we can start using Eclipse CDT for C/C++ development, 12 | we need to have a proper GCC compiler on our system. We can have ‘MinGW’ compiler on our machine that will be used by eclipse. 13 | img4 14 | step 2: add it to environment path variable 15 | img1 16 | Step 3: download eclipse (https://www.eclipse.org/downloads/) 17 | img2 18 | Step 4: install eclipse 19 | img3 20 | Step 5: open eclipse 21 | img5 22 | Step 6:click on files then click on c++ project 23 | img8 24 | Step 7: give the name to project(cpp program) 25 | -Here you can specify the name of the project. You can select an Empty project or a sample “Hello World” application project. 26 | img9 27 | Step 8: write a program 28 | img10 29 | Step 9: click on green play button to execute the code (img11) 30 | In this tutorial, we have seen the features, installation, configuration, and development using Eclipse CDT IDE. 31 | Although Eclipse IDE is primarily used for Java development, we can also use it for development using other programming languages like C/C++, PHP, Perl, Python to name a few. -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img1.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img10.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img11.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img2.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img3.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img4.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img5.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img6.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img7.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img8.png -------------------------------------------------------------------------------- /Documentation/Installing IDE- Eclipse for C++/img9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE- Eclipse for C++/img9.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/Steps to install CodeBlocks for C++.txt: -------------------------------------------------------------------------------- 1 | Steps to install Eclipse for C++ 2 | ---------------------------------------------------------------------------------------------------- 3 | 4 | 5 | Pre-requisites: 6 | -system with processor intel i3 or ryzen 3 and above 7 | -ram: 4gb and above 8 | -internet connectivity to download eclipse and some packages 9 | ---------------------------------------------------------------------------------------------------------------------- 10 | step 1: Download ans Install Mingw (https://sourceforge.net/projects/mingw/) 11 | Eclipse CDT uses C/C++ Compiler. Hence before we can start using Eclipse CDT for C/C++ development, 12 | we need to have a proper GCC compiler on our system. We can have ‘MinGW’ compiler on our machine that will be used by eclipse. 13 | 14 | step 2: add it to environment path variable 15 | 16 | Step 3: download codeblocks 17 | img(1),img(2) 18 | Step 4: install codeblocks 19 | img(3),img(4),img(5) 20 | Step 5: open codeblocks 21 | img(7) 22 | Step 6:click on files then click on c++ project 23 | img(9) 24 | Step 7: give the name to project(cpp program) 25 | -Here you can specify the name of the project. You can select an Empty project or a sample “Hello World” application project. 26 | img(14) 27 | Step 8: write a program 28 | img(14) 29 | Step 9: click on yes button to execute the code (img(15)) 30 | In this tutorial, we have seen the features, installation, configuration, and development using CodeBlocks IDE. 31 | we can also use it for development using other programming languages like C/C++, PHP, Perl, Python to name a few. -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (1).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (14).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (14).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (15).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (15).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (2).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (3).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (4).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (5).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (5).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (6).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (6).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (7).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (7).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-CodeBlocks_c++/img (9).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-CodeBlocks_c++/img (9).png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/Agreement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/Agreement.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/Download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/Download.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/Hello.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/Hello.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/components.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/file.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/finish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/finish.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/fonts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/fonts.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/installing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/installing.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/language.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/language.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/location.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/output.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/select_lang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/select_lang.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Dev C++/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Dev C++/success.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/1.PNG -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/10.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/11.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/2.PNG -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/3.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/4.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/5.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/6.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/7.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/8.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-Turbo_C++/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-Turbo_C++/9.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/Check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/Check.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/Installation_completion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/Installation_completion.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/Installer_Vscode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/Installer_Vscode.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/Installer_mingw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/Installer_mingw.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/SYstemSetting.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/SYstemSetting.jfif -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/SourceForge.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/SourceForge.jfif -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/Steps to install Vscode For C++.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/Steps to install Vscode For C++.docx -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/SystemProperties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/SystemProperties.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/apply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/apply.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/bin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/bin.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/env_variables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/env_variables.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/env_variables2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/env_variables2.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/ex1.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/ex2.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/ex3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/ex3.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/extensions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/extensions.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/min.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/mingw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/mingw.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/mingw2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/mingw2.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/mingw3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/mingw3.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/mingwPath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/mingwPath.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/path.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/requirements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/requirements.png -------------------------------------------------------------------------------- /Documentation/Installing IDE-VScode/vscode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing IDE-VScode/vscode.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/apt setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/apt setup.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/build.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/gpg key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/gpg key.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/installing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/installing.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/key add success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/key add success.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/output.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/stable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/stable.png -------------------------------------------------------------------------------- /Documentation/Installing Sublime in Linux/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/Installing Sublime in Linux/terminal.png -------------------------------------------------------------------------------- /Documentation/Template_TXT_Reference.md: -------------------------------------------------------------------------------- 1 | ### Main Topic - Your chosen topic name here 2 | 3 | ### Sub-topic - Your chosen sub-topic name here 4 | 5 |
6 | 7 | ### Pre-requisites 8 | - Point 1 9 | - Point 2 10 | 11 |
12 | 13 | ### Formal Definition 14 | #### *You can refer to an authentic source for this. This line is for developer info. Kindly remove it before creating a PR 15 | 16 |
17 | 18 | ### Easy and Clear Explanation (along with examples) 19 | #### *Kindly provide your explanation in a casual language like you explain something to a friend. Also comments more than 50% lines of the code. This line is for developer info. Kindly remove it before creating a PR. 20 | 21 |
22 | 23 | ### Solved Questions(Maxiumum 2) 24 | #### *Easy to Medium level - This line is for developers info. Kindly remove it before creating a PR 25 | 26 |
27 | 28 | ### Practice Questions(Minimum 2) 29 | #### *Medium to Hard level - This line is for developers info. Kindly remove it before creating a PR 30 | - Question 1 31 | - Question 2 32 | 33 | 34 | -------------------------------------------------------------------------------- /Documentation/images/cpp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/images/cpp.png -------------------------------------------------------------------------------- /Documentation/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/images/logo.png -------------------------------------------------------------------------------- /Documentation/images/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/images/question.png -------------------------------------------------------------------------------- /Documentation/images/write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/images/write.png -------------------------------------------------------------------------------- /Documentation/write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Documentation/write.png -------------------------------------------------------------------------------- /Dynamic Programming/Editdistance.cpp: -------------------------------------------------------------------------------- 1 | //Given two strings str1 and str2 and perform add, remove, replace operations that can performed on str1. Find minimum number of operations required to convert ‘str1’ into ‘str2’ 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int min(int x,int y,int z) //Function to Calculate the minimum of three number 8 | { 9 | return min(min(x,y),z); //Return minimum of three number 10 | } 11 | 12 | int editdistance(string s1,string s2,int n,int m) 13 | { 14 | if(n==0) //If length of string1 is zero then return lenght of string2 15 | { 16 | return m; 17 | } 18 | if(m==0) 19 | { 20 | return n; //If length of string2 is zero then return lenght of string1 21 | } 22 | if(s1[n-1]==s2[m-1]) 23 | { 24 | return editdistance(s1,s2,n-1,m-1); //If last char of both string is same the return digonal element 25 | } 26 | else{ 27 | return 1+min(editdistance(s1,s2,n-1,m),editdistance(s1,s2,n,m-1),editdistance(s1,s2,n-1,m-1)); //Else return min of ((x-1,y-1),(x,y-1),(x-1,y)) +1 28 | } 29 | 30 | } 31 | //Driver code 32 | int main() 33 | { 34 | string s1; 35 | cout<<"Enter the string 1"<>s1; 37 | 38 | string s2; 39 | cout<<"Enter the string 2"<>s2; 41 | int n=s1.size(); 42 | int m=s2.size(); 43 | 44 | cout<<"Total operations to convert string 1 to string 2 IS "< 3 | using namespace std; 4 | 5 | 6 | int max(int a, int b) //Function to calculate the maximum 7 | { 8 | if(a>b) 9 | { 10 | return a; 11 | } 12 | else 13 | { 14 | return b; 15 | } 16 | } 17 | 18 | int eggdrop(int n, int k) 19 | { 20 | if (k == 1 || k == 0) //If Number of floor is 1 or 0 then return number of florr 21 | return k; 22 | 23 | if (n == 1) //If the number of egg is 1 then return number of floors 24 | return k; 25 | 26 | int min = INT_MAX, res; 27 | 28 | for (int i = 1; i <= k; i++) { 29 | res = max(eggdrop(n - 1, i - 1),eggdrop(n, k - i)); //If egg breaks then floor will k-1 and egg will be n-1 30 | if (res < min) //Else floor will be k-i and number of eggs will be same 31 | min = res; 32 | } 33 | 34 | return min + 1; 35 | } 36 | 37 | int main() 38 | { 39 | int n; 40 | cout<<"Enter the number of Eggs "<>n; 42 | int k; 43 | cout<<"Enter the number of Floors "<>k; 45 | 46 | cout< 3 | #include 4 | using namespace std; 5 | 6 | int lps(char*seq,int i,int j) 7 | { 8 | if(i==j) //If string has only one value then return 1; 9 | { 10 | return 1; 11 | } 12 | 13 | if(seq[i]==seq[j] && i+1==j) //If string has only one value then return 2; 14 | { 15 | return 2; 16 | } 17 | 18 | if(seq[i]==seq[j]) //If string has only first and last character are same; 19 | { 20 | return lps(seq,i+1,j-1)+2; 21 | } 22 | else{ 23 | return max(lps(seq,i+1,j),lps(seq,i,j-1)); //If string has only first and last character are not same then call the recursive function; 24 | } 25 | 26 | 27 | } 28 | 29 | //Driver class 30 | int main() 31 | { 32 | int n; 33 | cout<<"Enter the number of characters"<>n; 35 | char seq[n]; 36 | cout<<"Enter the String"<>seq; 38 | 39 | cout<<"longest palindromic subsequence is "< 9 | using namespace std; 10 | 11 | // Preprocessing helps the code run faster 12 | #define fl(i, a, b) for (int i = a; i < b; i++) 13 | 14 | // Function that return 15 | int maxProfit(int* prices, int size) 16 | { 17 | // maxProfit adds up the difference between 18 | // adjacent elements if they are in increaisng order 19 | int maxProfit = 0; 20 | // The loop starts from 1 21 | // as its comparing with the previous 22 | fl(i, 1, size) if (prices[i] > prices[i - 1]) maxProfit 23 | += prices[i] - prices[i - 1]; 24 | return maxProfit; 25 | } 26 | 27 | // Driver Function 28 | int main() 29 | { 30 | int prices[] = { 100, 180, 260, 310, 40, 535, 695 }; 31 | int N = sizeof(prices) / sizeof(prices[0]); 32 | cout << maxProfit(prices, N) << endl; 33 | return 0; 34 | } 35 | // This code is contributed by Rajat Jain 36 | 37 | -------------------------------------------------------------------------------- /Dynamic Programming/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Dynamic Programming/Welcome.txt -------------------------------------------------------------------------------- /Exception Handling/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Exception Handling/Welcome.txt -------------------------------------------------------------------------------- /File Handling/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/File Handling/Welcome.txt -------------------------------------------------------------------------------- /Game Theory/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Game Theory/Welcome.txt -------------------------------------------------------------------------------- /GeeksForGeeks/Cuttingrod.cpp: -------------------------------------------------------------------------------- 1 | //Given a rod of length n inches and an array of prices that includes prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | //Function to find the maximum of two integers 8 | int max(int a, int b){ 9 | if(a>b) 10 | { 11 | return a; 12 | } 13 | else{ 14 | return b; 15 | } 16 | } 17 | 18 | //Function to find the maximum profit 19 | int cutRod(int price[], int n) 20 | { 21 | int maxprofit; 22 | int arr[n+1]; //Let an array of size n+1 to store different profit possible. 23 | arr[0] = 0; //Intilaise the first element of let array be 0 24 | 25 | 26 | for (int i = 1; i<=n; i++) 27 | { 28 | maxprofit = INT_MIN; 29 | for (int j = 0; j < i; j++) 30 | { 31 | maxprofit = max(maxprofit, price[j] + arr[i-j-1]); //Find the max profit possible by checking all the possible cases 32 | 33 | } 34 | 35 | arr[i] = maxprofit; //Store all the profit in acsending order in array 36 | } 37 | 38 | return arr[n]; //return the last element of array 39 | } 40 | 41 | //Driver code 42 | int main() 43 | { 44 | int n; 45 | cout<<"Enter the length of Rod "<>n; 47 | int profit[n]; 48 | cout<<"Enter the profit of different pieces of Rod "<>profit[i]; //Input the profit of different pieces of Rod 52 | } 53 | cout <<"Maximum profit "< 3 | using namespace std; 4 | // } Driver Code Ends 5 | class Solution 6 | { 7 | public: 8 | // arr: input array 9 | // n: size of array 10 | //Function to find the sum of contiguous subarray with maximum sum. 11 | int maxSubarraySum(int arr[], int n) 12 | { 13 | int curr_sum = arr[0]; 14 | int max_sum = arr[0]; 15 | for (int i = 1; i < n; i++) 16 | { 17 | curr_sum = max(curr_sum + arr[i], arr[i]); 18 | max_sum = max(max_sum, curr_sum); 19 | } 20 | // Your code here 21 | return max_sum; 22 | } 23 | }; 24 | // { Driver Code Starts. 25 | int main() 26 | { 27 | int t, n; 28 | cin >> t; //input testcases 29 | while (t--) //while testcases exist 30 | { 31 | cin >> n; //input size of array 32 | int a[n]; 33 | for (int i = 0; i < n; i++) 34 | cin >> a[i]; //inputting elements of array 35 | Solution ob; 36 | cout << ob.maxSubarraySum(a, n) << endl; 37 | } 38 | } 39 | // } Driver Code Ends -------------------------------------------------------------------------------- /GeeksForGeeks/Median_in_sorted_rowwise_matrix/Question.md: -------------------------------------------------------------------------------- 1 | ## Question Statement: 2 | Given a row wise sorted matrix of size RxC where R and C are always odd, find the median of the matrix. 3 | 4 | ## Exmaples: 5 | Example 1: 6 | 7 | Input: 8 | R = 3, C = 3 9 | M = [[1, 3, 5], 10 | [2, 6, 9], 11 | [3, 6, 9]] 12 | 13 | Output: 5 14 | 15 | Explanation: 16 | Sorting matrix elements gives us 17 | {1,2,3,3,5,6,6,9,9}. Hence, 5 is median. 18 | 19 | 20 | Example 2: 21 | 22 | Input: 23 | R = 3, C = 1 24 | M = [[1], [2], [3]] 25 | Output: 2 26 | 27 | 28 | ### Expected Time Complexity: O(32 * R * log(C)) 29 | ### Expected Auxiliary Space: O(1) 30 | 31 | 32 | ## Constraints: 33 | - 1<= R,C <=150 34 | - 1<= matrix[i][j] <=2000 35 | 36 | ## Probelm link: 37 | https://practice.geeksforgeeks.org/problems/median-in-a-row-wise-sorted-matrix1527/1 -------------------------------------------------------------------------------- /GeeksForGeeks/Median_sorted_array_diff_size/Question.md: -------------------------------------------------------------------------------- 1 | https://practice.geeksforgeeks.org/problems/median-of-2-sorted-arrays-of-different-sizes/1# 2 |
Given two sorted arrays array1 and array2 of size m and n respectively. Find the median of the two sorted arrays. 3 | 4 |
Example 1: 5 | 6 |
Input: 7 |
m = 3, n = 4 8 |
array1[] = {1,5,9} 9 |
array2[] = {2,3,6,7} 10 |
Output: 5 11 |
Explanation: The middle element for 12 |
{1,2,3,5,6,7,9} is 5 13 |
Example 2: 14 | 15 |
Input: 16 |
m = 2, n = 4 17 |
array1[] = {4,6} 18 |
array2[] = {1,2,3,5} 19 |
Output: 3.5 20 |
Your Task: 21 |
The task is to complete the function MedianOfArrays() that takes array1 and array2 as input and returns their median. 22 |
23 |
Can you solve the problem in expected time complexity? 24 |
25 |
Expected Time Complexity: O(min(log n, log m)). 26 |
Expected Auxiliary Space: O((n+m)/2). 27 |
28 |
Constraints: 29 |
0 ≤ m,n ≤ 10^4 30 |
1 ≤ array1[i], array2[i] ≤ 10^5 31 | -------------------------------------------------------------------------------- /GeeksForGeeks/Minimum-Platform.cpp: -------------------------------------------------------------------------------- 1 | // Program to find minimum number of platforms 2 | // required on a railway station 3 | #include 4 | using namespace std; 5 | 6 | 7 | class Solution{ 8 | public: 9 | //Function to find the minimum number of platforms required at the 10 | //railway station such that no train waits. 11 | int findPlatform(int arr[], int dep[], int n) 12 | { 13 | // Your code here 14 | sort(arr,arr+n); //Sort the Array of Arrival Time 15 | sort(dep,dep+n); //Sort the Array of Departure Time 16 | int i=1,j=0; //Two pointer one for arr and other for dep array 17 | int plat=1,result=1; //plat contains platform needed and result will contian the final answer to the problem 18 | while(i>t; 42 | while(t--) 43 | { 44 | int n; 45 | cin>>n; 46 | int arr[n]; 47 | int dep[n]; 48 | for(int i=0;i>arr[i]; 50 | for(int j=0;j>dep[j]; 52 | } 53 | Solution ob; 54 | cout < 4 | using namespace std; 5 | 6 | 7 | // Function to find the maximum increasing sum 8 | int maxincsum(int arr[], int n) 9 | { 10 | int max = 0; 11 | int mis[n]; //let an array of size n 12 | 13 | 14 | for (int i = 0; i < n; i++ ) 15 | { 16 | mis[i] = arr[i]; //Store given array in mis array 17 | } 18 | 19 | 20 | 21 | for (int i = 1; i < n; i++ ) 22 | for (int j = 0; j < i; j++ ) 23 | if (arr[i] > arr[j] && mis[i] < mis[j] + arr[i]) //If array is increasing and sum is increasing 24 | { 25 | mis[i] = mis[j] + arr[i]; //Add the value in mis array 26 | } 27 | 28 | 29 | for (int i = 0; i < n; i++ ) //find the max sum in array 30 | { 31 | if ( max < mis[i] ){ 32 | max = mis[i]; 33 | 34 | } 35 | 36 | } 37 | 38 | return max; //Return the maximum sum 39 | } 40 | 41 | // Driver Code 42 | int main() 43 | { 44 | int n; 45 | cout<<"Enter the size of array "<>n; //Input the size of array; 47 | int arr[n]; 48 | cout<<"Enter the elements of array "<>arr[i]; //Input the elements of array; 52 | } 53 | 54 | cout << "Sum of maximum sum increasing " < 5 | using namespace std; 6 | int main() 7 | { 8 | int a[50],b[50],i,j,N; 9 | cout<<"How many elements you want to enter:-"; 10 | cin>>N; // inputting number of elements 11 | cout<<"Enter any "<>a[i]; //inputting the elements that we want to swap 15 | } 16 | cout<<"Reverse of Array:- "; 17 | 18 | for(i=N-1,j=0; i>=0;i--,j++) 19 | { 20 | b[i]=a[j]; //swapping the elements 21 | } 22 | for(i=0; i 11 | #include 12 | using namespace std; 13 | 14 | int main() { 15 | int i; 16 | long l; 17 | char c; 18 | float f; 19 | double d; 20 | scanf("%d %ld %c %f %lf", &i, &l, &c, &f, &d); 21 | 22 | printf("%d\n%ld\n%c\n%f\n%lf", i, l, c, f, d); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Hackerrank/Birthday_Cake_Candles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. 4 | They will only be able to blow out the tallest of the candles. Count how many candles are tallest. 5 | 6 | https://www.hackerrank.com/challenges/birthday-cake-candles/problem 7 | 8 | */ 9 | 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int n,temp=0,count=0,i; 17 | cin>>n; 18 | vector array(n); 19 | for(i=0;i>array[i]; 22 | } 23 | 24 | sort(array.begin(),array.end()); //rearrange the elements in ascending order 25 | temp=array[n-1]; 26 | 27 | for(i=0;i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int y; 8 | cin >> y; 9 | string s = "12.09."; //as Programmer's day will always be in the month of september, we create a string already containing date 12 and month September 10 | 11 | if (y < 1918){ 12 | if (y%4 == 0){ //before 1918, leap year was considered only when the year was divisible by 4 13 | s[0] = '1'; //so the 256th day on leap year will be 12.09.yyyy, hence keeping the string as it is 14 | s[1] = '2'; 15 | } 16 | else { 17 | s[0] = '1'; //the 256th day on a non-leap year will fall on the 13.09.yyyy 18 | s[1] = '3'; 19 | } 20 | } 21 | else if (y == 1918){ 22 | s[0] = '2'; 23 | s[1] = '6'; 24 | //in year 1918, the days 1-13th Feb are not counted, so we'll have to add 13 to 13th Sep, which is 26.09.1918 25 | } 26 | else { 27 | if (y%400 == 0 || (y%4 == 0) && (y%100 != 0)){ //after 1918, the condition for leap year becomes that it should be divisible by 400 or should be divisible by 4 and not by 100 28 | s[0] = '1'; //so the 256th day on leap year will be 12.09.yyyy, hence keeping the string as it is 29 | s[1] = '2'; 30 | } 31 | else{ 32 | s[0] = '1'; //the 256th day on a non-leap year will fall on the 13.09.yyyy 33 | s[1] = '3'; 34 | } 35 | } 36 | cout << s << y << endl; //appending the year to the string 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Hackerrank/For Loop/For Loop.cpp: -------------------------------------------------------------------------------- 1 | // QUESTION:- 2 | 3 | // A for loop is a programming language statement which allows code to be repeatedly executed. 4 | 5 | // The syntax is 6 | 7 | // for ( ; ; ) 8 | // 9 | // expression_1 is used for intializing variables which are generally used for controlling the terminating flag for the loop. 10 | // expression_2 is used to check for the terminating condition. If this evaluates to false, then the loop is terminated. 11 | // expression_3 is generally used to update the flags/variables. 12 | // A sample loop is 13 | 14 | // for(int i = 0; i < 10; i++) { 15 | // ... 16 | // } 17 | // In this challenge, you will use a for loop to increment a variable through a range. 18 | 19 | 20 | 21 | // Logic:- You will be given two positive integers, a and b (a<=b), separated by a newline. 22 | 23 | // For each integer n, in the interval [a,b]: 24 | // If 1<=n<=9 then print the English representation of it in lowercase. That is "one" for 1, "two" for 2, and so on. 25 | // Else if n>9 and it is an even number, then print "even". 26 | // Else if n>9 and it is an odd number, then print "odd". 27 | 28 | 29 | 30 | 31 | // SOLUTION:- For loop based. 32 | 33 | 34 | #include 35 | using namespace std; 36 | int main() 37 | { // Variable a,b 38 | int a,b; 39 | string c[]={"","one","two","three","four","five","six","seven","eight","nine"}; 40 | cin>>a>>b; //Here cpp takes users value and run it. 41 | for(int i=a;i<=b;i++) // Here for loop starts. 42 | cout<<((i<=9)?c[i]:((i%2==0)?"even":"odd"))< 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int arr[7][7]; 12 | int sum(int stx , int sty) //add up each element from subarrays for a square of 3 * 3. 13 | { 14 | return arr[stx][sty] + arr[stx][sty+1] + arr[stx][sty+2] + arr[stx+1][sty+1] + arr[stx+2][sty] + arr[stx+2][sty+1] + arr[stx+2][sty+2]; 15 | } 16 | int main() { 17 | int ans = -100; 18 | for(int i = 0 ; i < 6 ; i++){ // Taking the input for the matrix 19 | for(int j = 0 ; j < 6 ; j++){ 20 | cin >> arr[i][j]; 21 | } 22 | } 23 | 24 | for(int i = 0 ; i < 4 ; i++){ // first for loop to iterate over the array. 25 | for(int j = 0 ; j < 4 ; j++){ // second for loop to iterate over subarray. 26 | ans = max(ans , sum(i,j)); // ans variable that will hold highest sum of the hourglass. 27 | } 28 | } 29 | 30 | cout << ans << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Hackerrank/Variable-sized-arrays/question.md: -------------------------------------------------------------------------------- 1 | ## Variable Sized Arrays 2 |
3 | 4 | - link -- 5 | [Variable sized arrays](https://www.hackerrank.com/challenges/variable-sized-arrays/problem) -------------------------------------------------------------------------------- /Hackerrank/Variable-sized-arrays/solution.cpp: -------------------------------------------------------------------------------- 1 | //solution 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main() { 12 | 13 | int noofarr,noofqueries; //initializing no:of arr variable and no:of queries 14 | cin>>noofarr>>noofqueries; //getting input 15 | vector>bigarr; //declaring an vector array which contains vector arrays as elements 16 | for(int i=0;i>arrsize; 19 | vectorsmallarr; 20 | for(int j=0;j>ele; 22 | smallarr.push_back(ele); 23 | } 24 | bigarr.push_back(smallarr); 25 | 26 | } 27 | for(int k=0;k>arrindex>>eleindex; 30 | cout< Solution::findSubstring(string A, const vector &B) { 11 | unordered_map map; 12 | unordered_map tempMap; 13 | int n = B.size(); 14 | vector result; 15 | if(n == 0) return result; 16 | 17 | int m = B[0].length(); 18 | if(A.length() < m*n) return result; 19 | 20 | for(int i=0;i>& dungeon) { 4 | vector> dp(dungeon.size(), vector(dungeon[0].size(),-1)); //dp value is minimum initial health to get to the end from i, j 5 | return DFS(dungeon,0,0,dp); 6 | } 7 | 8 | int DFS(vector>& dungeon, int i, int j, vector>& dp){ 9 | if (i == dungeon.size()-1 && j == dungeon[0].size()-1) //If we are on the last cell return the health needed to pass the cost if negative, otherwise return 1 if positive 10 | return dungeon[i][j] > 0? 1 : 1 - dungeon[i][j]; 11 | if (dp[i][j] != -1) //If we already calculated the cell previously, use the value 12 | return dp[i][j]; 13 | 14 | if (i == dungeon.size()-1) //If in the last row, only DFS with j increments 15 | return dp[i][j] = max(1, DFS(dungeon,i,j+1,dp)-dungeon[i][j]); 16 | if (j == dungeon[0].size()-1) //If in the last column, onlly DFS with i increments 17 | return dp[i][j] = max(1, DFS(dungeon,i+1,j,dp)-dungeon[i][j]); 18 | 19 | //If not in the last row or column, return minimum of lateral or vertical step-DFS 20 | return dp[i][j] = max(1, min(DFS(dungeon,i+1,j,dp)-dungeon[i][j],DFS(dungeon,i,j+1,dp)-dungeon[i][j])); 21 | } 22 | }; -------------------------------------------------------------------------------- /LeetCode/ Dungeon Game/readme.md: -------------------------------------------------------------------------------- 1 | Question Link - https://leetcode.com/problems/dungeon-game/ -------------------------------------------------------------------------------- /LeetCode/3Sum/question.txt: -------------------------------------------------------------------------------- 1 | Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. 2 | 3 | Notice that the solution set must not contain duplicate triplets. 4 | 5 | 6 | 7 | Example 1: 8 | Input: nums = [-1,0,1,2,-1,-4] 9 | Output: [[-1,-1,2],[-1,0,1]] 10 | 11 | Example 2: 12 | Input: nums = [] 13 | Output: [] 14 | 15 | Example 3: 16 | Input: nums = [0] 17 | Output: [] 18 | 19 | 20 | Constraints: 21 | 0 <= nums.length <= 3000 22 | -10^5 <= nums[i] <= 10^5 -------------------------------------------------------------------------------- /LeetCode/3Sum/readme.md: -------------------------------------------------------------------------------- 1 | Question 2 | 3 | Link - [3Sum](https://leetcode.com/problems/3sum) -------------------------------------------------------------------------------- /LeetCode/Check If It Is a Straight Line.cpp: -------------------------------------------------------------------------------- 1 | //1232. Check If It Is a Straight Line 2 | //https://leetcode.com/problems/check-if-it-is-a-straight-line/ 3 | 4 | class Solution { 5 | public: 6 | bool checkStraightLine(vector>& coordinates) { 7 | //if points are two then return true 8 | if(coordinates.size()==2) 9 | return true; 10 | else{ 11 | int x1=coordinates[0][0],x2=coordinates[1][0],y1=coordinates[0] [1],y2=coordinates[1][1]; 12 | for(int i=2;i 8 | using namespace std; 9 | int main(){ 10 | 11 | // n = no. of stairs 12 | int n; 13 | cin>>n; 14 | 15 | int prev = 0; 16 | int cur = 1; 17 | int temp; 18 | 19 | for (int i = 0; i < n; i++) { 20 | temp = prev; 21 | prev = cur; 22 | cur += temp; 23 | } 24 | cout< findDuplicates(vector& nums) { 4 | vector v; 5 | int n=nums.size(),k; 6 | for(int i=0;i& gain) { 6 | //maximum altitude 7 | int ans = 0; 8 | //current altitude 9 | int altitude = 0; 10 | 11 | for(int i: gain){ 12 | altitude += i; 13 | //it checks if altitude is greater than max altitude(i.e., ans) if so, then variable ans is updated. 14 | ans = max(ans, altitude); 15 | } 16 | 17 | return ans; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /LeetCode/Fizz Buzz.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector fizzBuzz(int n) { 4 | vector str; 5 | //first check for divisiblity by 3 and 5 both then 3 and 5 6 | for(int i=1;i<=n;i++){ 7 | if(i%3==0 and i%5==0) 8 | str.push_back("FizzBuzz"); 9 | else if(i%3==0) 10 | str.push_back("Fizz"); 11 | else if(i%5==0) 12 | str.push_back("Buzz"); 13 | else 14 | str.push_back(to_string(i)); 15 | } 16 | return str; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/GenerateParentheses/generateparentheses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | // Member function will return the anwser of string datatype 8 | vector result; 9 | vector generateParenthesis(int n) { 10 | helper("", n, 0, 0); 11 | // Returning the finial answer 12 | return result; 13 | } 14 | void helper(string s, int n, int l, int r){ 15 | if (l < r || l > n || r > n) return; // exceed the bundary -> return 16 | if (l == n && r == n){ 17 | result.push_back(s); 18 | return; 19 | } 20 | helper(s + "(", n, l+1, r); 21 | helper(s + ")", n, l, r+1); 22 | } 23 | }; 24 | //Drive code starts. 25 | int main(){ 26 | Solution s; 27 | //calling method generateParentheses() with number. 28 | s.generateParenthesis(4); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /LeetCode/GenerateParentheses/ques.txt: -------------------------------------------------------------------------------- 1 | Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 2 | 3 | 4 | 5 | Example 1: 6 | 7 | Input: n = 3 8 | Output: ["((()))","(()())","(())()","()(())","()()()"] 9 | Example 2: 10 | 11 | Input: n = 1 12 | Output: ["()"] 13 | 14 | 15 | Constraints: 16 | 17 | 1 <= n <= 8 18 | -------------------------------------------------------------------------------- /LeetCode/Gray Code.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem Statement : 3 | 4 | An n-bit gray code sequence is a sequence of 2n integers where: 5 | 6 | Every integer is in the inclusive range [0, 2n - 1], 7 | The first integer is 0, 8 | An integer appears no more than once in the sequence, 9 | The binary representation of every pair of adjacent integers differs by exactly one bit, and 10 | The binary representation of the first and last integers differs by exactly one bit. 11 | Given an integer n, return any valid n-bit gray code sequence. 12 | 13 | */ 14 | 15 | 16 | #include 17 | using namespace std; 18 | 19 | class Solution { 20 | // Recursive function 21 | void recur(int num, int pos, vector& ans) { 22 | ans.push_back(num); // inserting the number in answer vector 23 | if (pos < 0) return; // if position is less than zero then no need to furthur call the function 24 | 25 | // setting the bits of number from pos to zero and calling the function recursively 26 | for (int i = pos; i >= 0; i--) 27 | recur((num | (1 << i)), i - 1, ans); // num | (1 << i) will set the i th bit 28 | } 29 | 30 | public: 31 | vector grayCode(int n) { 32 | vector ans; // defining the answer vector 33 | recur(0, n - 1, ans); // calling the recursive function 34 | 35 | return ans; // return the answer vector 36 | } 37 | }; 38 | 39 | 40 | int32_t main() { 41 | Solution solution; // creating a object of solution class 42 | 43 | int n; 44 | cin >> n; // taking the input 45 | vector ans = solution.grayCode(n); // calling the grayCode function of Solution class 46 | 47 | for (auto j : ans) 48 | cout << j << ' '; 49 | cout << endl; 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /LeetCode/House Robber/README.md: -------------------------------------------------------------------------------- 1 | #### Question link 2 | https://leetcode.com/problems/house-robber/ 3 | -------------------------------------------------------------------------------- /LeetCode/House Robber/question.txt: -------------------------------------------------------------------------------- 1 | You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night. 2 | 3 | Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: nums = [1,2,3,1] 10 | Output: 4 11 | Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3). 12 | Total amount you can rob = 1 + 3 = 4. 13 | 14 | Example 2: 15 | 16 | Input: nums = [2,7,9,3,1] 17 | Output: 12 18 | Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1). 19 | Total amount you can rob = 2 + 9 + 1 = 12. 20 | 21 | Constraints: 22 | 23 | 1 <= nums.length <= 100 24 | 0 <= nums[i] <= 400 25 | -------------------------------------------------------------------------------- /LeetCode/Interger To Roman/Question.txt: -------------------------------------------------------------------------------- 1 | Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. 2 | 3 | Symbol Value 4 | I 1 5 | V 5 6 | X 10 7 | L 50 8 | C 100 9 | D 500 10 | M 1000 11 | For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. 12 | 13 | Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used: 14 | 15 | I can be placed before V (5) and X (10) to make 4 and 9. 16 | X can be placed before L (50) and C (100) to make 40 and 90. 17 | C can be placed before D (500) and M (1000) to make 400 and 900. 18 | Given an integer, convert it to a roman numeral. 19 | 20 | 21 | 22 | Example 1: 23 | 24 | Input: num = 3 25 | Output: "III" 26 | Example 2: 27 | 28 | Input: num = 4 29 | Output: "IV" 30 | Example 3: 31 | 32 | Input: num = 9 33 | Output: "IX" 34 | Example 4: 35 | 36 | Input: num = 58 37 | Output: "LVIII" 38 | Explanation: L = 50, V = 5, III = 3. 39 | Example 5: 40 | 41 | Input: num = 1994 42 | Output: "MCMXCIV" 43 | Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. 44 | 45 | 46 | Constraints: 47 | 48 | 1 <= num <= 3999 -------------------------------------------------------------------------------- /LeetCode/Interger To Roman/Solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution 5 | { 6 | public: 7 | // Member function will return the anwser of string datatype 8 | string intToRoman(int number) 9 | { 10 | // Declaring an integer array of all type of possible numbers to convert it into Roman. 11 | int num[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000}; 12 | // Declearing a string array which will contain all type of possible Romans 13 | string s[] = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"}; 14 | int i = 12; 15 | string ans = ""; // Taking default answer as an empty string 16 | while (number > 0) // initiates the while loop. 17 | { 18 | int div = number / num[i]; 19 | number = number % num[i]; 20 | while (div--) 21 | { 22 | ans += s[i]; 23 | } 24 | i--; 25 | } 26 | return ans; // Returning the finial answer 27 | } 28 | }; 29 | 30 | // { Driver Code Starts. 31 | int main() 32 | { 33 | //calling method intToRoman() with number. 34 | Solution s; 35 | s.intToRoman(3); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /LeetCode/Interger To Roman/readme.md: -------------------------------------------------------------------------------- 1 | Link to the question - https://leetcode.com/problems/integer-to-roman/ -------------------------------------------------------------------------------- /LeetCode/Island perimeter/question.txt: -------------------------------------------------------------------------------- 1 | You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. 2 | 3 | Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). 4 | 5 | The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island. 6 | 7 | Input: grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]] 8 | Output: 16 9 | Explanation: The perimeter is the 16 yellow stripes in the image above. 10 | Example 2: 11 | 12 | Input: grid = [[1]] 13 | Output: 4 14 | Example 3: 15 | 16 | Input: grid = [[1,0]] 17 | Output: 4 18 | 19 | 20 | Constraints: 21 | 22 | row == grid.length 23 | col == grid[i].length 24 | 1 <= row, col <= 100 25 | grid[i][j] is 0 or 1. 26 | There is exactly one island in grid. -------------------------------------------------------------------------------- /LeetCode/Island perimeter/readme.md: -------------------------------------------------------------------------------- 1 | question link: https://leetcode.com/problems/island-perimeter/ -------------------------------------------------------------------------------- /LeetCode/Island perimeter/solution.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/island-perimeter/ 2 | 3 | class Solution { 4 | public: 5 | int islandPerimeter(vector>& grid) { 6 | int result=0; 7 | int row = grid.size(), col = grid[0].size(); // row and column 8 | if(row==0 || col==0) 9 | return 0; 10 | for(int i=0;i0 && grid[i][j-1]==1) // chek if has left block 19 | { 20 | result=result-2; 21 | } 22 | 23 | if(i>0 && grid[i-1][j]==1) // check if it has up block 24 | { 25 | result=result-2; 26 | } 27 | 28 | } 29 | } 30 | } 31 | return result; 32 | } 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /LeetCode/Jump Game II/Question.txt: -------------------------------------------------------------------------------- 1 | Given an array of non-negative integers nums, you are initially positioned at the first index of the array. 2 | 3 | Each element in the array represents your maximum jump length at that position. 4 | 5 | Your goal is to reach the last index in the minimum number of jumps. 6 | 7 | You can assume that you can always reach the last index. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: nums = [2,3,1,1,4] 14 | Output: 2 15 | Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. 16 | Example 2: 17 | 18 | Input: nums = [2,3,0,1,4] 19 | Output: 2 20 | 21 | 22 | Constraints: 23 | 24 | 1 <= nums.length <= 104 25 | 0 <= nums[i] <= 1000 -------------------------------------------------------------------------------- /LeetCode/Jump Game II/readme.md: -------------------------------------------------------------------------------- 1 | Question link : https://leetcode.com/problems/jump-game-ii/ -------------------------------------------------------------------------------- /LeetCode/Jump Game II/solution.cpp: -------------------------------------------------------------------------------- 1 | 2 | //https://leetcode.com/problems/jump-game-ii/ 3 | 4 | 5 | // Time complexity O(N) 6 | // Auxillary space O(1) 7 | 8 | /* 9 | Approach: 10 | 1.maxReach means the maximum we can reach from that particular index 11 | which is the index plus the value of the index (the jump value). 12 | So, we keep updating it in each iteration so that whenever we move forward, 13 | the variable stores the maximum we can reach by using maxReach = max(maxReach, nums[i]+i) 14 | 2.Also, at each iteration, we reduce our steps variable by 1. 15 | 3.So, in this solution, we return jumps+1 as our answer. 16 | */ 17 | 18 | class Solution { 19 | public: 20 | int jump(vector& nums) { 21 | if(nums.size()==1) 22 | return 0; 23 | int maxReach = nums[0]; 24 | int steps = nums[0]; 25 | int jumps = 0; 26 | for(int i=1;i& nums) { 4 | int n= nums.size(); //size of given vector 5 | 6 | bool dp[n]; //create a dp table of size equal n and initialize all values as false 7 | for(int i=0;i letterCombinations(string digits) { 29 | vectorphone={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; //create vector of string for each number in phone 30 | if(digits.empty()) 31 | return {}; //if input is empty return empty vector 32 | vectorresult; //store final result 33 | result.push_back(""); 34 | for(auto d:digits){ //for every digit 35 | vectortemp; //create temp vecotr to store string cur string and update in result vector 36 | for(auto s:phone[d-'0']){ 37 | for(auto r:result){ 38 | temp.push_back(r+s); //compute every combination of strings 39 | } 40 | } 41 | result.swap(temp); 42 | } 43 | return result; 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /LeetCode/Merge k Sorted Lists/question.txt: -------------------------------------------------------------------------------- 1 | 2 | You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. 3 | 4 | Merge all the linked-lists into one sorted linked-list and return it. 5 | 6 | 7 | 8 | Example 1: 9 | 10 | Input: lists = [[1,4,5],[1,3,4],[2,6]] 11 | Output: [1,1,2,3,4,4,5,6] 12 | Explanation: The linked-lists are: 13 | [ 14 | 1->4->5, 15 | 1->3->4, 16 | 2->6 17 | ] 18 | merging them into one sorted list: 19 | 1->1->2->3->4->4->5->6 20 | Example 2: 21 | 22 | Input: lists = [] 23 | Output: [] 24 | Example 3: 25 | 26 | Input: lists = [[]] 27 | Output: [] 28 | 29 | 30 | Constraints: 31 | 32 | k == lists.length 33 | 0 <= k <= 10^4 34 | 0 <= lists[i].length <= 500 35 | -10^4 <= lists[i][j] <= 10^4 36 | lists[i] is sorted in ascending order. 37 | The sum of lists[i].length won't exceed 10^4. -------------------------------------------------------------------------------- /LeetCode/Merge k Sorted Lists/readme.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/merge-k-sorted-lists/ -------------------------------------------------------------------------------- /LeetCode/MiddleLL.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/middle-of-the-linked-list/ 2 | 3 | #include 4 | using namespace std; 5 | class Node{//creating node 6 | public: 7 | int data; 8 | Node *next; 9 | }; 10 | class NodeOperation{ 11 | public: 12 | void pushNode(class Node** head_ref,int data_val){//adding elements to linked list 13 | class Node *new_node = new Node(); 14 | new_node->data = data_val; 15 | new_node->next = *head_ref; 16 | *head_ref = new_node; 17 | } 18 | 19 | void printNode(class Node *head){//printing linked list 20 | while(head != NULL){ 21 | cout <data << "->"; 22 | head = head->next; 23 | } 24 | cout << "NULL" << endl; 25 | } 26 | 27 | void printMiddle(class Node *head){//code to print the middle of linked list 28 | struct Node *slow_ptr = head; 29 | struct Node *fast_ptr = head; 30 | if (head!=NULL) 31 | { 32 | while (fast_ptr != NULL && fast_ptr->next != NULL) 33 | { 34 | fast_ptr = fast_ptr->next->next; 35 | slow_ptr = slow_ptr->next; 36 | } 37 | cout << "The middle element is [" << slow_ptr->data << "]" << endl; 38 | } 39 | } 40 | }; 41 | 42 | int main(){//main function 43 | class Node *head = NULL; 44 | class NodeOperation *temp = new NodeOperation(); 45 | for(int i=5; i>0; i--){//control loop to push elements into array 46 | temp->pushNode(&head, i); 47 | temp->printNode(head); 48 | temp->printMiddle(head); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /LeetCode/Permutation.cpp: -------------------------------------------------------------------------------- 1 | //Problem link:https://leetcode.com/problems/permutations/ 2 | class Solution { 3 | public: 4 | vector> result; 5 | 6 | // Backtracking 7 | void permutation(vector &nums,int i,int n){ 8 | if(i==n){ 9 | result.push_back(nums); 10 | return ; 11 | } 12 | 13 | for(int j=i;j<=n;j++){ 14 | swap( nums[i],nums[j]); 15 | permutation(nums,i+1,n); //index is increased by one so that swapping is done with next index element in further calls 16 | swap( nums[i],nums[j]); //swapping it back to original order after recursion call is over 17 | } 18 | } 19 | 20 | vector> permute(vector& nums) { 21 | 22 | permutation(nums,0,nums.size()-1); 23 | 24 | return result; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /LeetCode/Power-of-four/Readme.md: -------------------------------------------------------------------------------- 1 | Question Link- https://leetcode.com/problems/power-of-four/ 2 | -------------------------------------------------------------------------------- /LeetCode/Power-of-four/Solution.cpp: -------------------------------------------------------------------------------- 1 | //Given an integer n, return true if it is a power of four. Otherwise, return false. 2 | #include 3 | using namespace std; 4 | #define ll long long 5 | bool isPowerOfFour(int n) { 6 | 7 | if(n<=0) 8 | { 9 | return false; //Negative Numbers can't be a power of 4 10 | } 11 | return !(n&(n-1)) and n%3==1; //If a number is power of 2 then n7(n-1) is zero and if the number is power of 4 it always gives 1 when taken mod with 3 12 | 13 | 14 | } 15 | int main() { 16 | int n; 17 | cin>>n; //Taking Input the number 18 | bool ans=isPowerOfFour(n); 19 | if(ans) 20 | { 21 | cout<<"Yes "< findRepeatedDnaSequences(string s) { 30 | mapstore; 31 | vectorans; 32 | int i=0,n=s.length(); 33 | while(i+10<=n){ 34 | string sub=s.substr(i++,10); //extracting all substring of length from string 35 | store[sub]++; //increment count if same string occurs 36 | if(store[sub]==2) //check if it is repeated again if so then add it to vector 37 | ans.push_back(sub); 38 | } 39 | return ans; //return final vector 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /LeetCode/ReverseInteger/ques.txt: -------------------------------------------------------------------------------- 1 | Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0. 2 | 3 | Assume the environment does not allow you to store 64-bit integers (signed or unsigned). 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: x = 123 10 | Output: 321 11 | Example 2: 12 | 13 | Input: x = -123 14 | Output: -321 15 | Example 3: 16 | 17 | Input: x = 120 18 | Output: 21 19 | Example 4: 20 | 21 | Input: x = 0 22 | Output: 0 23 | 24 | 25 | Constraints: 26 | 27 | -2^31 <= x <= 2^31 - 1 -------------------------------------------------------------------------------- /LeetCode/ReverseInteger/reverseInteger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution{ 5 | public: 6 | // Member function will return the anwser of int datatype 7 | int reverse(int x){ 8 | int rev=0; 9 | while(x!=0){ 10 | int digit=x%10; 11 | x/=10; 12 | 13 | if (rev > 2147483647/10){ 14 | return 0; 15 | } 16 | if (rev < -2147483647/10){ 17 | return 0; 18 | }rev=rev*10+digit; 19 | // Returning the finial answer 20 | }return rev; 21 | } 22 | }; 23 | // { Driver Code Starts. 24 | int main(){ 25 | Solution s; 26 | //calling method reverseI() with number. 27 | s.reverse(4); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /LeetCode/Search Insert Position.cpp: -------------------------------------------------------------------------------- 1 | //https://leetcode.com/problems/search-insert-position/ 2 | class Solution { 3 | public: 4 | int searchInsert(vector& nums, int target) { 5 | //Apply Binary search on array for target value and for position return low value; 6 | int low=0; 7 | int high=nums.size()-1; 8 | while(low<=high){ 9 | int mid=(low+high)/2; 10 | if(nums[mid]>target) 11 | high=mid-1; 12 | else if(nums[mid]=0;i--){ 7 | if(k>25){ //check balance k greater than 25 if it is then add 'z' at end 8 | s[i]='z'; 9 | k=k-25; 10 | } 11 | else{ //else we add the character if it is less than equal 25 12 | s[i]=97+k; 13 | break; 14 | } 15 | } 16 | return s; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /LeetCode/Sorting Ascending.cpp: -------------------------------------------------------------------------------- 1 | //sort the colors input by the user. take red as 0, white as 1 and blue as 2 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | cout<<"No. of entries: \n"; 7 | int n; 8 | cin>>n; 9 | int a[n],t;//an array with size n and a temporary variable that will later be used for swapping 10 | cout<<"Enter "< "; 14 | cin>>a[i]; 15 | cout<<"\n"; 16 | }// shows output as: "->0 17 | // ->2 18 | // ->1 and so on 19 | for(int i=0;i0){ 7 | int digit=x%10; 8 | sum+=digit; 9 | mul*=digit; 10 | x=x*10; 11 | } 12 | return mul-sum; 13 | } 14 | }; -------------------------------------------------------------------------------- /LeetCode/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/LeetCode/Welcome.txt -------------------------------------------------------------------------------- /LeetCode/ZigZagConversion/ques.txt: -------------------------------------------------------------------------------- 1 | The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 2 | 3 | P A H N 4 | A P L S I I G 5 | Y I R 6 | And then read line by line: "PAHNAPLSIIGYIR" 7 | 8 | Write the code that will take a string and make this conversion given a number of rows: 9 | 10 | string convert(string s, int numRows); 11 | 12 | 13 | Example 1: 14 | 15 | Input: s = "PAYPALISHIRING", numRows = 3 16 | Output: "PAHNAPLSIIGYIR" 17 | Example 2: 18 | 19 | Input: s = "PAYPALISHIRING", numRows = 4 20 | Output: "PINALSIGYAHRPI" 21 | Explanation: 22 | P I N 23 | A L S I G 24 | Y A H R 25 | P I 26 | Example 3: 27 | 28 | Input: s = "A", numRows = 1 29 | Output: "A" 30 | 31 | 32 | Constraints: 33 | 34 | 1 <= s.length <= 1000 35 | s consists of English letters (lower-case and upper-case), ',' and '.'. 36 | 1 <= numRows <= 1000 -------------------------------------------------------------------------------- /LeetCode/trappingRainWater.cpp: -------------------------------------------------------------------------------- 1 | 2 | //https://leetcode.com/problems/trapping-rain-water/ 3 | 4 | class Solution { 5 | public: 6 | int trap(vector& height) { 7 | 8 | int n = height.size(); 9 | int total=0; 10 | int left = 0, right = n-1; //Taking first element as left and last element as right 11 | 12 | int maxLeft=0, maxRight=0; //Consider max height for left and right respectively 13 | 14 | while(left <= right){ //Check till left element is small or equal to right 15 | 16 | if(height[left]<=height[right]){ //check till height for left is less or equal to right 17 | 18 | if(height[left] >= maxLeft) //Height at Left is greater or equal to maximum value at left 19 | maxLeft = height[left]; 20 | else 21 | total += maxLeft - height[left]; //Add the difference between maximum value and height at left 22 | 23 | left++; //Increment from left side 24 | } 25 | else{ 26 | if(height[right] >= maxRight){ //Height at Right is greater or equal to maximum value at right 27 | maxRight = height[right]; 28 | } 29 | else 30 | total += maxRight - height[right]; //Add the difference between maximum value and height at right 31 | 32 | right--; //Decrement from right side 33 | } 34 | } 35 | return total; //Return the total units of water trapped between bars 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /Number Theory/Special_Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int factorial(int n){ 5 | if (n==0) 6 | return 1; 7 | return (n*factorial(n-1)); 8 | } 9 | 10 | int sum(int num){ 11 | int s=0; 12 | while(num>0){ 13 | s=s+factorial(num%10); 14 | num=num/10; 15 | } 16 | return s; 17 | } 18 | 19 | int main(){ 20 | int number,add; 21 | cin>>number; 22 | add=sum(number); 23 | if(add==number) 24 | cout< 13 | 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | int n=5; 19 | for(int i=1;i<=n;i++) 20 | { 21 | for(int j=1;j<=i;j++) 22 | { 23 | cout<<"*"; 24 | } 25 | cout< //class for handling input and output 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x, y; //temporary variables to store the row and column number 9 | for(x=0 ; x<=8 ; x++) //to change row 10 | { 11 | for(y=0 ; y<=11 ; y++) //to change column 12 | { 13 | if((y!=5&&y!=6)&&x==0) 14 | { 15 | cout << "$"; //printing statement 16 | } 17 | else if(((y==5||y==6)&&x!=8)||(x==6&&(y==0||y==1))||(x==7&&(y==1||y==2))||(x==8&&(y==3||y==4))) 18 | { 19 | cout << "#"; //printing statement 20 | } 21 | else 22 | { 23 | cout << " "; //printing statement for space 24 | } 25 | } 26 | cout << "\n"; //printing statement for next line 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Pattern printing/Letter W.cpp: -------------------------------------------------------------------------------- 1 | //Write a program to print letter W exactly as shown 2 | #include //class responsible for handling input and output 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x,y; //temporary integer type variables to store row and column number 9 | for(x=0 ; x<=5 ; x++) //To change the rows 10 | { 11 | for(y=0 ; y<=22 ; y++) //To change the columns 12 | { 13 | if((x==y)||(y==(x+1))||((22-y)==x)||((22-y)==(x+1))) 14 | { 15 | cout << "@"; //printing statement 16 | } 17 | else if(((x+y)==11)||((y-x)==11)) 18 | { 19 | cout << "#"; //printing statement 20 | } 21 | else 22 | { 23 | cout << " "; //printing statement for space 24 | } 25 | } 26 | cout << "\n"; //printing statement for next line 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Pattern printing/Letter_A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This code prints the letter A, as shown below. 3 | 4 | ** 5 | ** ** 6 | ** ** 7 | ** ** 8 | ** ** 9 | **########** 10 | ** ** 11 | ** ** 12 | ** ** 13 | 14 | There are 6 distinct patterns featured in printing the letter A to console. 15 | If we define those patterns as strings, and also define the order in which 16 | they are printed, then we could iterate over the order and print the correct 17 | pattern each time, resulting in the correct output. (i.e., the letter A) 18 | */ 19 | #include 20 | 21 | int main() 22 | { 23 | std::string essentialStrings[6] = {" **", " ** **", " ** **", " ** **", "** **", "**########**"}; 24 | int n = 9; 25 | int printIndices[9] = {0, 1, 2, 3, 4, 5, 4, 4, 4}; 26 | for(int i=0; i < n; ++i) 27 | { 28 | std::cout << essentialStrings[ printIndices[i] ] << std::endl; 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Pattern printing/Letter_B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This code prints the letter B, as shown below. 3 | 4 | **##### 5 | ** ## 6 | ** ## 7 | ** ## 8 | **##### 9 | ** ## 10 | ** ## 11 | ** ## 12 | **##### 13 | 14 | There are 3 distinct patterns featured in printing the letter B to console. 15 | If we define those patterns as strings, and also define the order in which 16 | they are printed, then we could iterate over the order and print the correct 17 | pattern, resulting in the correct output. (i.e., the letter B) 18 | */ 19 | #include 20 | 21 | int main() 22 | { 23 | std::string essentialStrings[3] = {"**#####", "** ##", "** ##"}; 24 | int n = 9; 25 | int printIndices[9] = {0, 1, 2, 1, 0, 1, 2, 1, 0}; 26 | for(int i=0; i < n; ++i) 27 | { 28 | std::cout << essentialStrings[ printIndices[i] ] << std::endl; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Pattern printing/Letter_C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This code prints the letter C, as shown below. 3 | 4 | ##### 5 | ** ** 6 | ** ** 7 | ## 8 | ## 9 | ## 10 | ## 11 | ## 12 | ** ** 13 | ** ** 14 | ##### 15 | 16 | There are 4 distinct patterns featured in printing the letter C to console. 17 | If we define those patterns as strings, and also define the order in which 18 | they are printed, then we could iterate over the order and print the correct 19 | overall pattern, resulting in the correct output. (i.e., the letter C) 20 | */ 21 | #include 22 | 23 | int main() 24 | { 25 | std::string essentialStrings[4] = {" #####", " ** **", " ** **", "##"}; 26 | int n = 11; 27 | int printIndices[11] = {0, 1, 2, 3, 3, 3, 3, 3, 2, 1, 0}; 28 | for(int i=0; i < n; ++i) 29 | { 30 | std::cout << essentialStrings[ printIndices[i] ] << std::endl; 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Pattern printing/Letter_E.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to print the below pattern 2 | 3 | // ##$$$$$$$ 4 | // ## 5 | // ## 6 | // ## 7 | // ##$$$$$$$ 8 | // ## 9 | // ## 10 | // ## 11 | // ##$$$$$$$ 12 | 13 | #include 14 | using namespace std; 15 | 16 | int main() { 17 | // Printing the pattern 18 | 19 | // As the pattern is of 9x9 size, therefore a nested for-loop from 0-8 is peformed. 20 | 21 | for (int i = 0; i < 9; i++) 22 | { 23 | for (int j = 0; j < 9; j++) 24 | { 25 | // To print the first two # columns. 26 | if (j < 2) 27 | { 28 | cout << "#"; 29 | } 30 | 31 | // To print the $ rows. 32 | else if ((i == 0 or i == 4 or i == 8) and j >= 2) 33 | { 34 | cout << "$"; 35 | } 36 | 37 | // To print the empty spaces. 38 | else 39 | { 40 | cout << " "; 41 | } 42 | } 43 | 44 | cout << endl; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Pattern printing/Letter_F.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to print the below pattern 2 | 3 | // ##$$$$$$$ 4 | // ## 5 | // ## 6 | // ## 7 | // ##$$$$$$$ 8 | // ## 9 | // ## 10 | // ## 11 | // ## 12 | 13 | #include 14 | using namespace std; 15 | 16 | int main() { 17 | // Printing the pattern 18 | 19 | // As the pattern is of 9x9 size, therefore a nested for-loop from 0-8 is peformed. 20 | for (int i = 0; i < 9; i++) 21 | { 22 | for (int j = 0; j < 9; j++) 23 | { 24 | // To print the first two # columns. 25 | if (j < 2) 26 | { 27 | cout << "#"; 28 | } 29 | 30 | // To print the $ rows. 31 | else if ((i == 0 or i == 4) and j >= 2) 32 | { 33 | cout << "$"; 34 | } 35 | 36 | // To print the empty spaces. 37 | else 38 | { 39 | cout << " "; 40 | } 41 | } 42 | 43 | cout << endl; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Pattern printing/Letter_H.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to print the below pattern 2 | /* 3 | ## ## 4 | ## ## 5 | ## ## 6 | ## ## 7 | ##$$$$$## 8 | ## ## 9 | ## ## 10 | ## ## 11 | ## ## 12 | */ 13 | #include 14 | using namespace std; 15 | int main(){ 16 | //For printing the 9*9 letter H. 17 | for(int i = 0;i<9;i++){ 18 | for(int j = 0;j<9;j++){ 19 | //For printing the First two and last two columns. 20 | if(j<2 ||(j>=7 && j<9)){ 21 | cout << '#'; 22 | }else{ 23 | if(i==4){ 24 | //For printing the Middle Lyer of $ sign 25 | cout << '$'; 26 | }else{ 27 | cout << ' '; 28 | } 29 | } 30 | } 31 | cout << '\n'; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Pattern printing/Letter_I.cpp: -------------------------------------------------------------------------------- 1 | //C++ program to print the below pattern :- 2 | 3 | /* $$$$##$$$$ 4 | ## 5 | ## 6 | ## 7 | ## 8 | ## 9 | ## 10 | ## 11 | $$$$##$$$$ */ 12 | 13 | #include 14 | #define ll long long 15 | #define N 100005 16 | #define mod 1000000007 17 | #define INF 2147483647 18 | #define ln "\n" 19 | #define fast() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); 20 | using namespace std; 21 | int main() 22 | { 23 | fast(); 24 | 25 | // for printing the pattern I have used 3 distinct patterns for printing the letter I 26 | 27 | string S1[3] = {"$$$$##$$$$", " ##", "$$$$##$$$$"}; 28 | int number = 9; 29 | int print[9] = {0,1, 1, 1, 1, 1, 1, 1, 0}; //iterating over the correct sequence and printing the correct pattern 30 | for(int j=0; j < number ;j++) // for loop from 0 to n 31 | { 32 | cout << S1[ print[j] ] << ln; // prints the final pattern 33 | } 34 | return 0; 35 | } 36 | 37 | // This Code is contributed by Adarsh Kumar Singh (Username ----> Fury-MadMax) 38 | -------------------------------------------------------------------------------- /Pattern printing/Letter_K.cpp: -------------------------------------------------------------------------------- 1 | //Question: 2 | /* Write a CPP Program to print the below pattern: 3 | 4 | ## @@ 5 | ## @@ 6 | ## @@ 7 | ## @@ 8 | ##@@ 9 | ## @@ 10 | ## @@ 11 | ## @@ 12 | ## @@ 13 | 14 | */ 15 | #include 16 | using namespace std; 17 | 18 | 19 | int main(){ 20 | ios_base::sync_with_stdio(false); 21 | cin.tie(NULL); 22 | 23 | int n;//there are a total of n rows in the pattern 24 | cin>>n;//taking input as number of rows in the letter 25 | //loop for the first/upper half of the letter K 26 | for (int i = 0; i < n-n/2; i++) 27 | { 28 | cout<<"##";//printing first ## in every row 29 | for (int j = 0; j < n-n/2-i-1; j++) 30 | { 31 | cout<<" ";//printing spaces whihc decrease in the upper half 32 | } 33 | cout<<"@@"< is the "##" part - printed in a straight line for 7 times, for this we run a for loop , 16 | second-> is the "##&&&&&&&" part - this can be printed directly as printf("##&&&&&&&\n"). 17 | 18 | Hence we get the complete pattern. 19 | 20 | */ 21 | 22 | #include 23 | using namespace std; 24 | int main() 25 | { 26 | //To print ## 27 | for(int i=0; i < 7; ++i) //printing ## in this loop for 7 times (n = 0 to 7) 28 | { 29 | printf("##\n"); // in a straight line 30 | 31 | } 32 | printf("##&&&&&&&\n"); //print one line "##&&&&&&&" to complete the last line of the letter L 33 | 34 | return 0; //we get the letter L pattern with the charecters needed. 35 | } 36 | -------------------------------------------------------------------------------- /Pattern printing/Letter_M.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | CPP Program to print Letter M 3 | 4 | ##@@ @@## 5 | ## @@ @@ ## 6 | ## @@ @@ ## 7 | ## ## ## 8 | ## ## 9 | ## ## 10 | ## ## 11 | ## ## 12 | 13 | 14 | Letter M can be broken down into 3 parts 15 | - full length first ## column 16 | - half length V letter 17 | - full length last ## column 18 | */ 19 | #include 20 | 21 | using namespace std; 22 | 23 | int main() { 24 | int level = 8; 25 | int vLevel = level/2; 26 | 27 | int firstSpaces = 0, lastSpaces = 0, midSpaces = 0; 28 | int i, cols = 2 * vLevel + 2; 29 | 30 | //for printing pattern till last row 31 | for (i = 0; i < level; ++i) { 32 | cout << "##"; 33 | if (i < vLevel -1) { 34 | firstSpaces = i; 35 | lastSpaces = i; 36 | midSpaces = cols - firstSpaces - lastSpaces - 4; //for @@ and @@ 37 | 38 | //print leading spaces 39 | cout << string(firstSpaces, ' '); 40 | //print @@ 41 | cout << "@@"; 42 | 43 | //print mid spaces 44 | cout << string(midSpaces, ' '); 45 | 46 | //print @@ 47 | cout << "@@"; 48 | 49 | //print last spaces; 50 | cout << string(lastSpaces, ' '); 51 | } 52 | else if (i == vLevel -1) { //last level of V 53 | cout << string(i + 1, ' ') << "##" << string(i + 1, ' '); 54 | } 55 | else { 56 | cout << string(cols, ' '); 57 | } 58 | cout << "##"; 59 | cout << endl; 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Pattern printing/Letter_N.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This code prints the letter N, as shown below. 4 | 5 | ##@@ ## 6 | ## @@ ## 7 | ## @@ ## 8 | ## @@ ## 9 | ## @@ ## 10 | ## @@ ## 11 | ## @@ ## 12 | ## @@## 13 | 14 | LOGIC: 15 | We need to run nested loops here , like a matrix i for depth - 8, j for width - 8 16 | First is the straight line "##", 17 | that is covered by for (i = 0; i < 8; i++). 18 | for i = 0 - 19 | we get ##@@ ## 20 | i = 1 ## @@ ## 21 | i = 2 ## @@ ## 22 | . 23 | . 24 | . 25 | and so on 26 | counter increments on every completed cycle, 27 | j handles the pattern on the horizontal i.e. printing "@@" and the second line of "##". 28 | Hence we get the desired Pattern N. 29 | 30 | */ 31 | 32 | #include 33 | using namespace std; 34 | 35 | // function to print the letter N Pattern 36 | void printN() 37 | 38 | { 39 | int i, j, counter = 0; 40 | 41 | //to print ## and @@ 42 | for (i = 0; i < 8; i++) // taking i<8 to print "##" in a straight line, 7 times (n = 0 to 8). 43 | { 44 | cout <<"##"; //this prints "##" in a striaght line . 45 | 46 | // to print "@@". 47 | for (j = 0; j <= 8; j++) 48 | { 49 | if (j == 8) // to print the second line of "##" 50 | cout <<"##"; 51 | else if (j == counter) 52 | cout <<"@@"; 53 | else 54 | cout <<" "; //else print " " according to the pattern N required. 55 | } 56 | counter++; 57 | cout <<"\n"; 58 | } 59 | } 60 | 61 | int main(int argc, char** argv) //To print the function N 62 | { 63 | printN(); // Letter N as output 64 | } 65 | -------------------------------------------------------------------------------- /Pattern printing/Letter_V.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | CPP Program to print Letter V 3 | 4 | 5 | @@ @@ 6 | @@ @@ 7 | @@ @@ 8 | @@ @@ 9 | @@ @@ 10 | @@ @@ 11 | @@@ 12 | */ 13 | 14 | #include 15 | 16 | using namespace std; 17 | 18 | int main() { 19 | int level = 7; 20 | 21 | int firstSpaces = 0, lastSpaces = 0, midSpaces = 0; 22 | int i, cols = 2 * level + 1; 23 | 24 | //for printing pattern till last row 25 | for (i = 0; i < level - 1; ++i) { 26 | firstSpaces = i; 27 | lastSpaces = i; 28 | midSpaces = cols - firstSpaces - lastSpaces - 4; //for @@ and @@ 29 | 30 | //print leading spaces 31 | cout << string(firstSpaces, ' '); 32 | //print @@ 33 | cout << "@@"; 34 | 35 | //print mid spaces 36 | cout << string(midSpaces, ' '); 37 | //print @@ 38 | cout << "@@"; 39 | //print last spaces; 40 | cout << string(lastSpaces, ' '); 41 | cout << endl; 42 | } 43 | //print last line 44 | cout << string(level - 1, ' ') << "@@@" << string(level - 1, ' ') << endl; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Pattern printing/Letter_X.cpp: -------------------------------------------------------------------------------- 1 | //C++ program to print the below pattern :- 2 | 3 | /* 4 | @@ ## 5 | @@ ## 6 | @@ ## 7 | @@ ## 8 | @@@ 9 | ## @@ 10 | ## @@ 11 | ## @@ 12 | ## @@ 13 | */ 14 | 15 | #include 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | int row,coloumn; 21 | 22 | for(row=0; row<9; row++) // here 9 is the total no. of rows. 23 | { 24 | for(coloumn=0; coloumn<9; coloumn++) // here 9 is the total no. of coloumns. 25 | { 26 | if(row==4 && coloumn==4) 27 | cout << "@@@"; // printing @@@ in the middle of the letter when rows=4 & coloumns=4 28 | 29 | else if(row==coloumn) // prints the required characters when number of rows equals number of columns 30 | cout << "@@"; 31 | 32 | else if((row+coloumn)==8) // prints the required characters when number of rows + number of columns equals (total rows-1) 33 | cout << "##"; 34 | 35 | else 36 | cout << " "; // prints a whitespace at places where characters are not printed. 37 | } 38 | cout << "\n"; // prints a newline at the end of each row. 39 | } 40 | return 0; 41 | } 42 | 43 | 44 | // This Code is contributed by Harshvardhan Singh (Username ----> cyberskull99297) 45 | -------------------------------------------------------------------------------- /Pattern printing/Letter_Y.cpp: -------------------------------------------------------------------------------- 1 | //C++ program to print the below pattern :- 2 | 3 | /* 4 | @@ ## 5 | @@ ## 6 | @@ ## 7 | @@ ## 8 | @@## 9 | @@ 10 | @@ 11 | @@ 12 | @@ 13 | */ 14 | 15 | #include 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | int row,column; 21 | 22 | for(row=0; row<9; row++) // here 9 is the total no. of rows. 23 | { 24 | for(column=0; column<=9; column++) // here 9 is the total no. of columns. 25 | { 26 | if(row==4 && column==4) // prints '@@' when rows=4 & column=4 27 | cout << "@@"; 28 | 29 | else if(row==column && row<5) // prints the required character when the number of row is less than 5. 30 | cout << "@@"; 31 | 32 | else if((row+column)==9 && row<5) // prints the required character when the number of row is less than 5. 33 | cout << "##"; 34 | 35 | else if(column==5 && row>=5) // prints the required character when the number of row is greater than or equal to 5. 36 | cout << "@@"; 37 | 38 | else 39 | cout << " "; // prints a whitespace at places where characters are not printed. 40 | 41 | } 42 | cout << "\n"; // prints a newline at the end of each row. 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | // This Code is contributed by Harshvardhan Singh (Username ----> cyberskull99297) 49 | -------------------------------------------------------------------------------- /Pattern printing/Letter_Z.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This code will print pattern like this...... 4 | 5 | @@@@@@@@@ 6 | ## 7 | ## 8 | ## 9 | ## 10 | ## 11 | ## 12 | @@@@@@@@@ 13 | 14 | */ 15 | 16 | #include 17 | using namespace std; 18 | 19 | int main() { 20 | // your code goes here 21 | int x,y; 22 | // For printing 8*9 letter Z 23 | for(x=0;x<8;x++){ 24 | for(y=0;y<9;y++){ 25 | 26 | if(x==0 || x==7){ 27 | // For printing top and bottom horizontal line of letter Z using '@' 28 | cout<<"@"; 29 | } 30 | else{ 31 | // For printing slant line of letter Z using '#' 32 | if(y==(9-x-2)){ 33 | cout<<"##"; 34 | y++; 35 | } 36 | else{ 37 | cout<<" "; 38 | } 39 | } 40 | } 41 | cout<<"\n"; 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Pattern printing/butterfly Pattern.cpp: -------------------------------------------------------------------------------- 1 | // Make a butterfly pattern 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cout<<"Enter the value of n: "; 10 | cin>>n; // taken a input from user 11 | for(int i=1;i<=n;i++){ //used for loop for * 12 | for(int j=1;j<=i;j++){ 13 | cout<<"*"; //printed * 14 | } 15 | int space=2*n-2*i; 16 | for(int j=1;j<=space;j++){ // used for loop for Space 17 | cout<<" "; //printed space 18 | } 19 | for(int j=1;j<=i;j++){ //again used for loop for * 20 | cout<<"*"; // printed * 21 | } 22 | cout<=1;i--){ //used for loop for * 25 | for(int j=i;j>=1;j--){ 26 | cout<<"*"; //printed * 27 | } 28 | int space=2*n-2*i; 29 | for(int j=space;j>=1;j--){ // used for loop for Space 30 | cout<<" "; //printed space 31 | } 32 | for(int j=i;j>=1;j--){ //again used for loop for * 33 | cout<<"*"; //printed * 34 | } 35 | cout< 3 | using namespace std; 4 | // Recursive function to return gcd of a and b 5 | int gcd(int a, int b){ 6 | if (a == 0) 7 | return b; 8 | if (b == 0) 9 | return a; 10 | if (a == b) //base case of recursion 11 | return a; 12 | if (a > b) 13 | return gcd(a-b, b); 14 | return gcd(a, b-a); 15 | } 16 | 17 | int main(){ 18 | int a = 98, b = 56; 19 | cout<<"GCD of "< 5 | using namespace std; 6 | 7 | // Function to print first n rows of Pascal's triangle 8 | void printPascal(int Row_num) 9 | { 10 | int arr[Row_num][Row_num]; 11 | 12 | for (int i = 0; i < Row_num; i++) 13 | { 14 | for (int j = 0; j <= i; j++) 15 | { 16 | if (i == j || j == 0) //Making first and last element of Every row as 1 17 | arr[i][j] = 1; 18 | else 19 | arr[i][j] = arr[i-1][j - 1] + arr[i- 1][j]; //Adding the element of pascal triangle by two corresponding elements 20 | cout << arr[i][j] << " "; 21 | } 22 | cout <>n; 46 | cout< 2 | using namespace std; 3 | 4 | int factorial(int i){ 5 | if(i==1) 6 | return 1; 7 | 8 | return i*factorial(i-1); 9 | 10 | } 11 | 12 | int main(){ 13 | int number; 14 | cout<<"Enter number : "; 15 | cin>>number; 16 | cout< 2 | using namespace std; 3 | // Question: 4 | // Sort the elements of the array in non-decreasing order using insertion sort. 5 | 6 | // This function is called by reference. 7 | void insertionSort(vector& nums) 8 | { 9 | int i, key, j, n=nums.size(); 10 | for (i = 1; i < n; i++) 11 | { 12 | // To sort the array we will first pick the ith element as key. 13 | // And find the proper position for it. 14 | // The position before that all elements in the array are smaller than key. 15 | // We will shift all the elements from that position to right of it. 16 | key = nums[i]; 17 | j = i - 1; 18 | 19 | // This while loop will shift the elements in right. 20 | while (j >= 0 && nums[j] > key) 21 | { 22 | // j+1th element takes the value of jth element 23 | nums[j + 1] = nums[j]; 24 | j = j - 1; 25 | } 26 | 27 | // The loop will stop once we find the correct position. 28 | // And j+1 is the correct position for that particular element. 29 | nums[j + 1] = key; 30 | } 31 | } 32 | 33 | int main() 34 | { 35 | int n; 36 | cin>>n; 37 | 38 | vector nums(n); 39 | for(int i=0; i>nums[i]; 41 | } 42 | 43 | insertionSort(nums); 44 | for(int i=0; i 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | 18 | //number of elements 19 | int n; 20 | cin>>n; 21 | 22 | int arr[n]; 23 | for(int i=0;i>arr[i]; 25 | 26 | for(int i=0;i 18 | # include 19 | # include 20 | using namespace std; 21 | 22 | int main() { 23 | 24 | int n,x,i,j; 25 | cin>>n; 26 | int array[n]; 27 | 28 | // vector even stores even index elements of array. 29 | // vector odd stores odd index elements of array. 30 | 31 | vector even,odd; 32 | for(x=0;x>array[x]; 34 | if(x%2==0){ 35 | even.push_back(array[x]); 36 | } 37 | else{ 38 | odd.push_back(array[x]); 39 | } 40 | } 41 | 42 | // Sorting both the vectors in ascending order 43 | 44 | sort(even.begin(),even.end()); 45 | sort(odd.begin(),odd.end()); 46 | 47 | i=0; 48 | j=odd.size()-1; 49 | 50 | // If index is even take value from even vector 51 | // Else take value from last of odd vector 52 | 53 | 54 | for(x=0;x 5 | using namespace std; 6 | 7 | void printOrder(int arr[], int n,string s) 8 | { 9 | // sorting the array 10 | sort(arr, arr + n); 11 | if(s=="AD"||s=="ad") 12 | { 13 | // printing first half in ascending 14 | // order 15 | for (int i = 0; i < n / 2; i++) 16 | cout << arr[i] << " "; 17 | 18 | // printing second half in descending 19 | // order 20 | for (int j = n - 1; j >= n / 2; j--) 21 | cout << arr[j] << " "; 22 | } 23 | else 24 | { 25 | 26 | // printing first half in Descending 27 | // order 28 | for (int i = n - 1; i>= n / 2; i--) 29 | cout << arr[i] << " "; 30 | 31 | // printing second half in Ascending 32 | // order 33 | for (int j = 0; j < n / 2; j++) 34 | cout << arr[j] << " "; 35 | } 36 | } 37 | 38 | 39 | int main() 40 | { 41 | int m; 42 | int arr[50]; 43 | string s; 44 | cout<<"enter Sorting Style "; 45 | cin>>s; 46 | cout<<"enter how many elements "; 47 | cin>>m; 48 | cout<<"Enter Element "; 49 | for(int i=0;i>arr[i]; 53 | } 54 | 55 | printOrder(arr,m,s); 56 | 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Sorting/Welcome.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SarthakKeshari/CPP-Questions-and-Solutions/b3097685322caac5124ecfbfd41a221fb6bc8318/Sorting/Welcome.txt -------------------------------------------------------------------------------- /String Handling/Longestcommonsequenec.cpp: -------------------------------------------------------------------------------- 1 | //You are given two strings. You need to print the longest common subsequence with tabulation method. 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | const int N=1e2+2; //Taking a large number 7 | int dp[N][N]; //Intialise a dp table 8 | 9 | int lcs(string&s1,string&s2,int n,int m) //Function to calculate the LIS 10 | { 11 | if(n==0 || m==0) //If length of s1 or s2 ise zero then return zero 12 | { 13 | return 0; 14 | } 15 | 16 | if(dp[n][m]!=-1) //If value is already calculated then return that 17 | { 18 | return dp[n][m]; 19 | } 20 | 21 | if(s1[n-1]==s1[m-1]) //If last element is equal then add 1 in diagonal element 22 | { 23 | dp[n][m]=1+lcs(s1,s2,n-1,m-1); 24 | } 25 | 26 | else{ 27 | dp[n][m]=max(lcs(s1,s2,n-1,m),lcs(s1,s2,n,m-1)); //Else Calculate max from (i-1,y) and (i,y-1) of 2d array 28 | } 29 | return dp[n][m]; 30 | } 31 | 32 | //driver function 33 | int main() 34 | { 35 | for(int i=0;i>s1; 46 | cout<<"Enter the String String 2"<>s2; 48 | int n=s1.size(); 49 | int m=s2.size(); 50 | 51 | cout< 3 | #include 4 | #include 5 | using namespace std; 6 | const int N=1e5+2; //Taking a large number 7 | int dp[N]; //Intialise a dp table 8 | 9 | int lis(vector&a,int n) //Function to calculate the LIS 10 | { 11 | if(dp[n]!=-1) //If value is already calculated then return that 12 | { 13 | return dp[n]; 14 | } 15 | else 16 | { 17 | dp[n]=1; //Else take it as 1 18 | } 19 | 20 | for(int i=0;ia[i]) //If an value is less then last Element the increase dp 23 | { 24 | dp[n]=max(dp[n],1+lis(a,i)); //Call Recursive function 25 | } 26 | } 27 | return dp[n]; //return dp value 28 | } 29 | //driver function 30 | int main() 31 | { 32 | int n; 33 | cout<<"Enter the number of Elements is Array"<>n; 35 | for(int i=0;ia(n); 40 | cout<<"Enter the Elements"<>a[i]; //Input value by user 45 | } 46 | 47 | cout<// library used for string 2 | #include 3 | #include // library used for type casting 4 | using namespace std; 5 | int main() 6 | { 7 | string s; 8 | cout<<"Enter an n digit number\n"; 9 | cin>>s; 10 | int l=s.size(),c=0;// c is counter used to count fixed digits each time 11 | string a[l];// new array to arrange all possible combinations, which will be equal to the number of digits in the number 12 | a[0]=s;// first combination will be the original number 13 | cout<>b;// assigning value from object to int variable 31 | if(b>max) 32 | max=b; 33 | } 34 | cout<<"\nThe greatest combination is: "< 6 | 7 | # 1) Form 1 8 | ### Issue Id you have worked upon - 9 | Kindly write your answer here 10 | 11 | ### Briefly explain your program logic - 12 | Kindly write your answer here 13 | 14 | ### Screenshots(Attach 2 screenshots of your own input and output) - 15 | Attach here 16 | 17 | 18 |
19 | 20 | ### Checklist: 21 | Eg - If your code follow the below guidelines. Kindly change [] to [x] 22 | 23 | All the conditions should be fulfilled for considering your code for merging - 24 | 25 | - [] I have mentioned the question as comment in my solution file.
26 | - [] My code follows the guidelines of this project.
27 | - [] I have performed a self-review of my own code.
28 | - [] I have commented my code.
29 | - [] My code gives the correct output.
30 | - [] I confirm that I have not copied the code from anywhere. In case its found that I have copied even after successful merge then I can be banned from the repository and hacktoberfest.
31 | 32 | 33 | - [] I affirm that I strictly follow contributing guidelines and code of conduct. 34 | 35 |
36 | 37 | # 2) Form 2 38 | ### Issue Id you have worked upon - 39 | Kindly write your answer here 40 | 41 |
42 | 43 | ### Checklist: 44 | Eg - If your code follow the below guidelines. Kindly change [] to [x] 45 | 46 | All the conditions should be fulfilled for considering your Pull Request for merging - 47 | 48 | - [] I have performed a self-review of my documentation.
49 | 50 | - [] I affirm that I strictly follow contributing guidelines and code of conduct. 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /website_name.txt: -------------------------------------------------------------------------------- 1 | CodersArena 2 | 3 | Arena is basically is spanish word. It's defined as a level area surrounded by seating, in which sports, entertainments, and other public events are held. So, I felt this word would be suitable for the website as it will be a place where coder community will come together for learning, challenges, and much more. --------------------------------------------------------------------------------