├── Assignment1
├── Test.txt
├── a.out
├── Power.cpp
├── Collecting the balls.cpp
└── Sortingskills.cpp
├── Leetcode
├── 718.cpp
├── Test.txt
├── codenation1.cpp
└── ARRAY
│ ├── Best Time to Buy and Sell Stock.cpp
│ ├── Contains Duplicate.cpp
│ ├── Two Sum.cpp
│ └── 3Sum.cpp
├── Number Theory
├── Test.txt
├── a.out
└── prime.cpp
├── String
├── input.txt
├── KMP
├── a.out
├── output.txt
├── 0000000000000183s.zip
├── Zalgo.cpp
└── KMP.cpp
├── Dynamic programming 2
├── Test.txt
├── maxprofit.cpp
├── a.out
├── Knapsack.cpp
├── Shortestsubsequence.cpp
├── LCS.cpp
├── Subsetsum.cpp
├── Editdistance.cpp
├── Miserman.cpp
├── Smallestsuperseq.cpp
├── Charlie.cpp
└── Maxprofit.cpp
├── DPandbitmasking
├── Test.txt
├── a.out
├── Mehta.cpp
├── Job.cpp
├── Diliema.cpp
├── Countingstrings.cpp
├── Stringmaker.cpp
└── Candy.cpp
├── adhoc problems
├── Test.txt
├── a.out
├── Circularlist.cpp
└── Lightupbulbs.cpp
├── Language-Tools
├── test.txt
├── a.out
├── Tripletsum
├── Extractunique
├── Pairsumtozero
├── Warm-reception
├── Different-names
├── tell-thepositions
├── Find-the-Unique-Element
├── Love-for-characters.cpp
├── Find-the-Unique-Element.cpp
├── Different-names.cpp
├── Repeat-and-Missing-Number -Array.cpp
├── Duplicateinarray.cpp
├── 3-zero-sum.cpp
├── Pairsumtozero.cpp
├── tell-thepositions.cpp
├── Warm-reception.cpp
└── Tripletsum.cpp
├── NeuralNetwork
├── bin
│ └── .gitignore
├── .gitignore
├── obj
│ └── main.obj
├── README.md
├── inc
│ ├── main.hpp
│ └── NeuralNetwork.hpp
├── Makefile
└── src
│ └── main.cpp
├── Greedy
├── Test.txt
├── a.out
├── Perimeter
├── minabsdiff.cpp
├── Nikunjanddonuts.cpp
├── Activityselection.cpp
├── Perimeter.cpp
├── Weightedjob.cpp
├── Problemdiscussion.cpp
└── FractionalKnapsack.cpp
├── Segment Trees
├── Test.txt
├── a.out
└── Minimuminsub.cpp
├── Advanced Graphs
├── Test.txt
├── a.out
├── Newyear.cpp
└── Monk.cpp
├── Graphs1
├── a.out
├── Test.txt
├── DFS.cpp
├── Prims MST.cpp
├── 3cycle.cpp
├── Allconnectedcomponents.cpp
├── getpathbfs.cpp
├── largestpiece.cpp
├── Kruskal MST.cpp
├── Board.cpp
├── bfs.cpp
├── strongly_connected_components.cpp
├── isconnected.cpp
├── haspath.cpp
└── Islandsc.cpp
├── fileupload
├── static
│ └── css
│ │ └── app.css
├── templates
│ ├── home.html
│ ├── upload.html
│ └── base.html
├── asgi.py
├── wsgi.py
└── urls.py
├── Backtracking
├── a.out
├── Test.txt
├── Rateinamaze.cpp
└── Nqueens.cpp
├── Cpp-STL-cheat-sheet.pdf
├── DP1(Very important)
├── a.out
├── Allzeroes
├── Adjacentbit
├── Vanya and gcd
├── angrychildren
├── Test.txt
├── staircase.cpp
├── Loot.cpp
├── mincount.cpp
├── Royandcoin.cpp
├── Maximumsum.cpp
├── Boredom.cpp
├── minchoc.cpp
├── coinchange.cpp
├── Vanya and gcd.cpp
├── angrychildren.cpp
├── Allzeroes.cpp
├── longestbitonicsubarray.cpp
└── Hasanandtrip.cpp
├── Interview Prep Books
├── Algorithms_3rd.pdf
└── epilight_cpp_new.pdf
├── Searching and sorting applications
├── a.out
├── Murderer
├── Momos market
├── Aggressive cows
├── Inversion Count
├── Distrributecandies
├── Test.txt
├── Inversion Count.cpp
├── Distrributecandies.cpp
├── Murderer.cpp
├── Tajmahalentry.cpp
├── Momos market.cpp
└── Aggressive cows.cpp
├── Time-complexity-analysis
├── K-Concatenation
├── Mindbedingproduct.cpp
└── K-Concatenation.cpp
├── C++ tricks for competitive programming (for C++ 11) - GeeksforGeeks.pdf
├── SelfCoded
├── 1528. Shuffle String.cpp
├── 1221. Split a String in Balanced Strings.cpp
├── 1486. XOR Operation in an Array.cpp
├── 1313. Decompress Run-Length Encoded List.cpp
├── 771 Jewels and Stones.cpp
├── 1281. Subtract the Product and Sum of Digits of an Integer.cpp
├── 1389. Create Target Array in the Given Order.cpp
├── 1342 Number of Steps to Reduce a Number to Zero.cpp
├── 1512 Number of Good Pairs.cpp
├── 1470 Shuffle the Array.cpp
├── 1295. Find Numbers with Even Number of Digits.cpp
├── 1431 Kids With the Greatest Number of Candies.cpp
├── 1108 Defanging an IP Address.cpp
├── 1365. How Many Numbers Are Smaller Than the Current Number.cpp
├── 1588. Sum of All Odd Length Subarrays.cpp
├── 1534. Count Good Triplets.cpp
├── LinkedList
│ ├── print_forward_and_reverse_ll.cpp
│ └── 1290. Convert Binary Number in a Linked List to Integer.cpp
└── Backtracking
│ └── 46. Permutations.cpp
├── Binary Search
├── BS on real values template
├── 1408C- Discrete Acceleration
└── 1199C-MP3
├── Prerequisites
├── Eveenodd.cpp
├── pre3.cpp
├── chakri.cpp
└── marbles.cpp
├── Trees
├── Postorder.cpp
├── Inorder Traversal.cpp
└── Preorder.cpp
├── Modulo Arithmetic
└── Balancesbst.cpp
├── Binary_Search_Program
├── Bit Manipulation
└── Unset.cpp
└── README.md
/Assignment1/Test.txt:
--------------------------------------------------------------------------------
1 | 68
--------------------------------------------------------------------------------
/Leetcode/718.cpp:
--------------------------------------------------------------------------------
1 | NA
2 |
--------------------------------------------------------------------------------
/Number Theory/Test.txt:
--------------------------------------------------------------------------------
1 | 4
--------------------------------------------------------------------------------
/String/input.txt:
--------------------------------------------------------------------------------
1 | aaaa
--------------------------------------------------------------------------------
/Leetcode/Test.txt:
--------------------------------------------------------------------------------
1 | NA
2 |
--------------------------------------------------------------------------------
/Leetcode/codenation1.cpp:
--------------------------------------------------------------------------------
1 | NA
2 |
--------------------------------------------------------------------------------
/Dynamic programming 2/Test.txt:
--------------------------------------------------------------------------------
1 | a
2 | ab
--------------------------------------------------------------------------------
/Dynamic programming 2/maxprofit.cpp:
--------------------------------------------------------------------------------
1 | jds
--------------------------------------------------------------------------------
/DPandbitmasking/Test.txt:
--------------------------------------------------------------------------------
1 | abc
2 | abc
3 | abc
--------------------------------------------------------------------------------
/adhoc problems/Test.txt:
--------------------------------------------------------------------------------
1 | 5 1 10
2 | 01000
--------------------------------------------------------------------------------
/Language-Tools/test.txt:
--------------------------------------------------------------------------------
1 | 9
2 | 0 7 2 5 4 7 1 3 6
--------------------------------------------------------------------------------
/NeuralNetwork/bin/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/Greedy/Test.txt:
--------------------------------------------------------------------------------
1 | 4
2 | 3 10 20
3 | 1 2 50
4 | 6 19 100
5 | 2 100 200
6 |
--------------------------------------------------------------------------------
/Segment Trees/Test.txt:
--------------------------------------------------------------------------------
1 | 5
2 | 1 8 4 6 8
3 | 4 8 6 3 7
4 | 4
5 | 1 4
6 | 2 4
7 | 3 4
8 | 1 5
--------------------------------------------------------------------------------
/Advanced Graphs/Test.txt:
--------------------------------------------------------------------------------
1 | 1
2 | 5 6 100
3 | 1 2 5
4 | 1 3 5
5 | 1 4 5
6 | 1 5 5
7 | 3 4 8
8 | 4 5 8
--------------------------------------------------------------------------------
/NeuralNetwork/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | *
3 | !/**/
4 | !*.*
5 | *.in
6 | *.out
7 | *.o
8 | !Makefile
--------------------------------------------------------------------------------
/String/KMP:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/String/KMP
--------------------------------------------------------------------------------
/Graphs1/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Graphs1/a.out
--------------------------------------------------------------------------------
/Greedy/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Greedy/a.out
--------------------------------------------------------------------------------
/String/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/String/a.out
--------------------------------------------------------------------------------
/Greedy/Perimeter:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Greedy/Perimeter
--------------------------------------------------------------------------------
/fileupload/static/css/app.css:
--------------------------------------------------------------------------------
1 | body {
2 | background-color: #5c848e;
3 | }
4 | h4
5 | {
6 |
7 | }
--------------------------------------------------------------------------------
/Assignment1/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Assignment1/a.out
--------------------------------------------------------------------------------
/Backtracking/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Backtracking/a.out
--------------------------------------------------------------------------------
/Graphs1/Test.txt:
--------------------------------------------------------------------------------
1 | 2
2 | 4 4 4
3 | 1 1
4 | 1 2
5 | 3 1
6 | 3 2
7 | 4 4 4
8 | 1 1
9 | 1 2
10 | 3 1
11 | 4 4
--------------------------------------------------------------------------------
/Number Theory/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Number Theory/a.out
--------------------------------------------------------------------------------
/Segment Trees/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Segment Trees/a.out
--------------------------------------------------------------------------------
/Advanced Graphs/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Advanced Graphs/a.out
--------------------------------------------------------------------------------
/DPandbitmasking/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DPandbitmasking/a.out
--------------------------------------------------------------------------------
/Language-Tools/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/a.out
--------------------------------------------------------------------------------
/adhoc problems/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/adhoc problems/a.out
--------------------------------------------------------------------------------
/Cpp-STL-cheat-sheet.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Cpp-STL-cheat-sheet.pdf
--------------------------------------------------------------------------------
/String/output.txt:
--------------------------------------------------------------------------------
1 | 0
2 | 0
3 | 1
4 | 1
5 | 2
6 | 2
7 | 3
8 | 3
9 | 4
10 | 4
11 | 0
12 | 2
13 | 3
14 | 0
15 | 2
16 |
--------------------------------------------------------------------------------
/DP1(Very important)/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DP1(Very important)/a.out
--------------------------------------------------------------------------------
/Language-Tools/Tripletsum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Tripletsum
--------------------------------------------------------------------------------
/NeuralNetwork/obj/main.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/NeuralNetwork/obj/main.obj
--------------------------------------------------------------------------------
/DP1(Very important)/Allzeroes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DP1(Very important)/Allzeroes
--------------------------------------------------------------------------------
/Dynamic programming 2/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Dynamic programming 2/a.out
--------------------------------------------------------------------------------
/Language-Tools/Extractunique:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Extractunique
--------------------------------------------------------------------------------
/Language-Tools/Pairsumtozero:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Pairsumtozero
--------------------------------------------------------------------------------
/Language-Tools/Warm-reception:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Warm-reception
--------------------------------------------------------------------------------
/String/0000000000000183s.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/String/0000000000000183s.zip
--------------------------------------------------------------------------------
/DP1(Very important)/Adjacentbit:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DP1(Very important)/Adjacentbit
--------------------------------------------------------------------------------
/Language-Tools/Different-names:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Different-names
--------------------------------------------------------------------------------
/fileupload/templates/home.html:
--------------------------------------------------------------------------------
1 | {% extends 'base.html' %}
2 |
3 | {% block content %}
4 |
Upload System
5 | {% endblock %}
--------------------------------------------------------------------------------
/DP1(Very important)/Vanya and gcd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DP1(Very important)/Vanya and gcd
--------------------------------------------------------------------------------
/DP1(Very important)/angrychildren:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/DP1(Very important)/angrychildren
--------------------------------------------------------------------------------
/Language-Tools/tell-thepositions:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/tell-thepositions
--------------------------------------------------------------------------------
/Interview Prep Books/Algorithms_3rd.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Interview Prep Books/Algorithms_3rd.pdf
--------------------------------------------------------------------------------
/Language-Tools/Find-the-Unique-Element:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Language-Tools/Find-the-Unique-Element
--------------------------------------------------------------------------------
/DP1(Very important)/Test.txt:
--------------------------------------------------------------------------------
1 | 5 4
2 | 1 2 3 5
3 | 3 1 3 2
4 | 4 5 2 3
5 | 5 5 3 2
6 | 4 4 3 4
7 | 6
8 | 1 1
9 | 2 5
10 | 4 5
11 | 3 5
12 | 1 3
13 | 1 5
--------------------------------------------------------------------------------
/Interview Prep Books/epilight_cpp_new.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Interview Prep Books/epilight_cpp_new.pdf
--------------------------------------------------------------------------------
/Searching and sorting applications/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/a.out
--------------------------------------------------------------------------------
/Time-complexity-analysis/K-Concatenation:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Time-complexity-analysis/K-Concatenation
--------------------------------------------------------------------------------
/Searching and sorting applications/Murderer:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/Murderer
--------------------------------------------------------------------------------
/Searching and sorting applications/Momos market:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/Momos market
--------------------------------------------------------------------------------
/Searching and sorting applications/Aggressive cows:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/Aggressive cows
--------------------------------------------------------------------------------
/Searching and sorting applications/Inversion Count:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/Inversion Count
--------------------------------------------------------------------------------
/Searching and sorting applications/Distrributecandies:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/Searching and sorting applications/Distrributecandies
--------------------------------------------------------------------------------
/Backtracking/Test.txt:
--------------------------------------------------------------------------------
1 | +-++++++++
2 | +A++-+++++
3 | +C------++
4 | +-++-+++++
5 | +-++-+++++
6 | +A++-+++++
7 | ++++-+++++
8 | ++++-+++++
9 | ++++++++++
10 | --L--L----
11 | CALIFORNIA;NIGERIA;CANADA;TELAVIV
--------------------------------------------------------------------------------
/C++ tricks for competitive programming (for C++ 11) - GeeksforGeeks.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GouravSingh2580/Competitive-Programming/HEAD/C++ tricks for competitive programming (for C++ 11) - GeeksforGeeks.pdf
--------------------------------------------------------------------------------
/Searching and sorting applications/Test.txt:
--------------------------------------------------------------------------------
1 | +-++++++++
2 | +-++++++++
3 | +-++++++++
4 | +-----++++
5 | +-+++-++++
6 | +-+++-++++
7 | +++++-++++
8 | ++------++
9 | +++++-++++
10 | +++++-++++
11 | LONDON;DELHI;ICELAND;ANKARA
--------------------------------------------------------------------------------
/NeuralNetwork/README.md:
--------------------------------------------------------------------------------
1 | # Simple Cpp Neural Network
2 |
3 | Simple Cpp Neural Network
4 |
5 | ## Commands:
6 |
7 | Build the project and put the binary in ./bin
8 |
9 | make
10 |
11 | Build and run the project
12 |
13 | make dev
14 |
15 | Only run the project
16 |
17 | make run
18 |
--------------------------------------------------------------------------------
/SelfCoded/1528. Shuffle String.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | string restoreString(string s, vector& in) {
4 |
5 | string z=s;
6 |
7 | for(int i=0;iUpload
5 |
10 | {% if url %}
11 | Uploaded file: {{ url }}
12 | {% endif %}
13 | {% endblock %}
--------------------------------------------------------------------------------
/SelfCoded/1486. XOR Operation in an Array.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int xorOperation(int n, int start) {
4 |
5 | vector v;
6 | for(int i=0;i decompressRLElist(vector& nums) {
4 |
5 | vector v;
6 | for(int i=1;i
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "NeuralNetwork.hpp"
10 |
11 | #define nl std::cout << std::endl;
12 |
13 | double relu(double x) {
14 | return x > 0 ? x : 0;
15 | }
16 |
17 | double dtanh(double value) {
18 | return -0.5 * ((tanh(value) - 1) * (tanh(value) + 1));
19 | }
20 |
21 | const char* message = "CPP-PROJECT TEMPLATE";
--------------------------------------------------------------------------------
/SelfCoded/1281. Subtract the Product and Sum of Digits of an Integer.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int subtractProductAndSum(int n) {
4 | int z=n;
5 | int x=n;
6 | int r=1;
7 | int m=0;
8 | while(z)
9 | {
10 | r*=z%10;
11 | z=z/10;
12 | }
13 | while(x)
14 | {
15 | m+=x%10;
16 | x=x/10;
17 | }
18 | return (r-m);
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/SelfCoded/1389. Create Target Array in the Given Order.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | vector createTargetArray(vector& nums, vector& index) {
4 | vector v(nums.size(),0);
5 | for(int i=0;i& nums) {
4 | int k=0;
5 |
6 | for(int i=0;i shuffle(vector& nums, int n) {
4 |
5 | vector v;
6 | v.push_back(nums[0]);
7 | int i=0;
8 | int x=1,y=1;
9 | for(int k=0;k& nums) {
4 | int k=0;
5 | int z=0;
6 | for(int i=0;i kidsWithCandies(vector& c, int e) {
4 | vector v;
5 |
6 | for(int i=0;i=*max_element(c.begin(), c.end()))
9 | {
10 | v.push_back(1);
11 | }
12 | else
13 | {
14 | v.push_back(0);
15 | }
16 | }
17 | return v;
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/SelfCoded/1108 Defanging an IP Address.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | string defangIPaddr(string a) {
4 |
5 | string v;
6 |
7 | for(int i=0;i smallerNumbersThanCurrent(vector& nums) {
4 | int k=0;
5 | vector v;
6 | for(int i=0;i &prices) {
8 | int paisa = 0;
9 | int minPrice = INT_MAX;
10 | for(int i = 0; i < prices.size(); i++){
11 | minPrice = min(minPrice, prices[i]);
12 | paisa = max(paisa, prices[i] - minPrice);
13 | }
14 | return paisa;
15 | }
16 | };
17 |
--------------------------------------------------------------------------------
/SelfCoded/1588. Sum of All Odd Length Subarrays.cpp:
--------------------------------------------------------------------------------
1 | class Solution {
2 | public:
3 | int sumOddLengthSubarrays(vector& arr) {
4 | int sum=0;
5 | int res=0;
6 | vector v;
7 | for(int i=0;i& arr, int a, int b, int c) {
4 | int z=0;
5 | for(int i=0;i
5 |
6 | using namespace std;
7 |
8 |
9 | int main( int argc , char ** argv )
10 | {
11 | ios_base::sync_with_stdio(false) ;
12 | cin.tie(NULL) ;
13 |
14 | int n;
15 | cin>> n;
16 | int* arr = new int[n];
17 | int sum1=0, sum2=0;
18 |
19 | for (int i = 0; i < n; ++i)
20 | {
21 | int a;
22 | cin>>a;
23 | arr[i] = a;
24 | if(i%2==0 && a%2==0){
25 | sum1+=a;
26 | }else if(i%2 != 0 && a%2!=0){
27 | sum2+=a;
28 | }
29 | }
30 |
31 | cout << sum1<<" "<
4 |
5 | using namespace std;
6 |
7 |
8 | int main( int argc , char ** argv )
9 | {
10 | ios_base::sync_with_stdio(false) ;
11 | cin.tie(NULL) ;
12 |
13 | int n;
14 | cin>>n;
15 |
16 | int sum = 0;
17 | int** arr = new int*[n];
18 | for (int i = 0; i < n; ++i)
19 | {
20 | arr[i]=new int[n];
21 | for (int j = 0; j < n; ++j)
22 | {
23 | cin>>arr[i][j];
24 | if(i==0 || j==0 || i==j || i==n-1 || j==n-1 || i+j==n-1){
25 | sum=sum+arr[i][j];
26 | }
27 | }
28 | }
29 |
30 | cout << sum << '\n';
31 |
32 |
33 |
34 | return 0 ;
35 |
36 |
37 |
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/Leetcode/ARRAY/Contains Duplicate.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Runtime: 44 ms, faster than 65.08% of C++ online submissions for Contains Duplicate.
3 | Memory Usage: 9 MB, less than 100.00% of C++ online submissions for Contains Duplicate.
4 | */
5 |
6 |
7 |
8 |
9 | class Solution {
10 | public:
11 | bool containsDuplicate(vector& v) {
12 | sort(v.begin(), v.end());
13 |
14 | if(v.size()==0)
15 | return false;
16 |
17 | for(int i=0;idata<<"-";
14 | head = head->next;
15 | }
16 | }
17 |
18 | //This function prints ll in reverse direction
19 | void backwardPrint(struct Node* head)
20 | {
21 | if(head == NULL) return;
22 | backwardPrint(head->next);
23 | cout<data<<"-";
24 | }
25 |
26 | /*
27 | Sample Input:
28 | 1
29 | 3
30 | 1
31 | 2
32 | 3
33 |
34 | Sample Output:
35 | 1-2-3-
36 | 3-2-1-
37 | */
38 |
--------------------------------------------------------------------------------
/Leetcode/ARRAY/Two Sum.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Runtime: 564 ms, faster than 10.10% of C++ online submissions for Two Sum.
3 | Memory Usage: 7 MB, less than 100.00% of C++ online submissions for Two Sum.
4 | */
5 |
6 |
7 |
8 | class Solution {
9 | public:
10 | vector twoSum(vector& nums, int target) {
11 | int a=0;
12 | int b=0;
13 | for(int i=0;i
11 |
12 | using namespace std;
13 |
14 |
15 | int main( int argc , char ** argv )
16 | {
17 | ios_base::sync_with_stdio(false) ;
18 | cin.tie(NULL) ;
19 |
20 | int n;
21 | cin>>n;
22 | int a[n];
23 | for(int i=0;i>a[i];
25 | int profit=0;
26 | for(int i=0;i0) && ((a[j]-a[i])>profit))
31 | {
32 | profit=a[j]-a[i];
33 | }
34 | }
35 | }
36 | cout<
11 |
12 | using namespace std;
13 |
14 |
15 | int main( int argc , char ** argv )
16 | {
17 | ios_base::sync_with_stdio(false) ;
18 | cin.tie(NULL) ;
19 |
20 | int n;
21 | cin>>n;
22 | int* arr=new int[n];
23 |
24 | for (int i = 0; i < n; ++i)
25 | {
26 | cin>>arr[i];
27 | }
28 |
29 | long double sum=0;
30 |
31 | for (int i = 0; i < n; ++i)
32 | {
33 | sum+=(long double)log10(arr[i]);
34 | }
35 |
36 | for (int i = 0; i < n; ++i)
37 | {
38 | cout << int(pow((long double)10.00, sum-log10(arr[i]))) << " ";
39 | }
40 |
41 |
42 |
43 | return 0 ;
44 |
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/Advanced Graphs/Newyear.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 | */
7 |
8 |
9 | #include
10 | using namespace std;
11 |
12 | int main(){
13 | int n, t;
14 | cin >> n >> t;
15 |
16 | // int **graph = new int*[n];
17 | // for(int i = 0; i < n; i++){
18 | // graph[i] = new int[n];
19 | // for(int j = 0; j < n; j++) graph[i][j] = 0;
20 | // }
21 |
22 | int position = 0;
23 |
24 | for(int i = 0; i < n-1; i++){
25 | if(position == t-1){
26 | cout << "YES" << endl;
27 | return 0;
28 | }
29 | int a;
30 | cin >> a;
31 | // graph[i][i+a] = 1;
32 | if(i == position) position += a;
33 | }
34 |
35 | cout << "NO" << endl;
36 | }
37 |
--------------------------------------------------------------------------------
/SelfCoded/Backtracking/46. Permutations.cpp:
--------------------------------------------------------------------------------
1 | // Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
2 |
3 | // Idk why I love this solution of mine so much ;)
4 |
5 | class Solution {
6 | public:
7 | vector> v;
8 | void permut(vector nums, int l, int r)
9 | {
10 | if(l==r) v.push_back(nums);
11 | else
12 | {
13 | for(int i=l;i<=r;i++)
14 | {
15 | swap(nums[l],nums[i]);
16 |
17 | permut(nums, l+1, r);
18 |
19 | swap(nums[l],nums[i]);
20 | }
21 | }
22 | }
23 | vector> permute(vector& nums) {
24 | permut(nums,0,nums.size()-1);
25 | return v;
26 | }
27 | };
28 |
--------------------------------------------------------------------------------
/Language-Tools/Love-for-characters.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 | Ayush loves the characters ‘a’, ‘s’, and ‘p’.
11 | He got a string of lowercase letters and he wants to find out how many times characters ‘a’, ‘s’, and ‘p’
12 | occurs in the string respectively. Help him find it out.
13 | */
14 | #include
15 |
16 | using namespace std;
17 |
18 |
19 | int main( int argc , char ** argv )
20 | {
21 | ios_base::sync_with_stdio(false) ;
22 | cin.tie(NULL) ;
23 |
24 | int n;
25 | cin>>n;
26 | string s;
27 | std::cin>>s;
28 |
29 | unordered_map m1;
30 |
31 | for (int i = 0; i < s.size(); ++i)
32 | {
33 | m1[s[i]]++;
34 | }
35 |
36 | cout << m1['a']<<" "<next;
20 | k++;
21 | }
22 | int sum=0;
23 | while(head!=NULL)
24 | {
25 | sum+=pow(2,k-1) * head->val;
26 | head=head->next;
27 | k--;
28 | }
29 | return sum;
30 | }
31 | };
32 |
--------------------------------------------------------------------------------
/Trees/Postorder.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | struct Node
4 | {
5 | int data;
6 | struct Node* left, *right;
7 | Node(int data)
8 | {
9 | this->data = data;
10 | left = right = NULL;
11 | }
12 | };
13 | void printPostorder(struct Node* node)
14 | {
15 | if (node == NULL)
16 | return;
17 |
18 | printPostorder(node->left);
19 | printPostorder(node->right);
20 | cout << node->data << " ";
21 | }
22 |
23 | int main()
24 | {
25 | struct Node *root = new Node(1);
26 | root->left = new Node(2);
27 | root->right = new Node(3);
28 | root->right->left = new Node(3);
29 | root->left->left= new Node(4);
30 | root->left->right = new Node(5);
31 |
32 | cout << "\nPostorder traversal of binary tree is \n";
33 | printPostorder(root);
34 |
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/Modulo Arithmetic/Balancesbst.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 |
7 | */
8 |
9 |
10 | #include
11 |
12 | using namespace std;
13 | int balancedBTs(int h) {
14 |
15 | if (h==0)
16 | {
17 | return 1;
18 | }
19 | if (h==1)
20 | {
21 | return 1;
22 | }
23 |
24 | long long x = balancedBTs(h-1)%1000000007;
25 | long long y = balancedBTs(h-2)%1000000007;
26 | long long temp = (long long)(((2*x)%1000000007)*(y%1000000007))+(long long)((x%1000000007)*(x%1000000007));
27 |
28 | long long ans = 0;
29 | ans += ((temp%1000000007))%(1000000007);
30 |
31 | return ans;
32 |
33 |
34 | }
35 |
36 | int main( int argc , char ** argv )
37 | {
38 | ios_base::sync_with_stdio(false) ;
39 | cin.tie(NULL) ;
40 |
41 | int h;
42 | cin >> h;
43 | int ans = balancedBTs(h);
44 | cout << ans << endl;
45 |
46 |
47 | return 0 ;
48 |
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Trees/Inorder Traversal.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | struct Node
6 | {
7 | int data;
8 | struct Node* left, *right;
9 | Node(int data)
10 | {
11 | this->data = data;
12 | left = right = NULL;
13 | }
14 | };
15 |
16 | void printInorder(struct Node* node)
17 | {
18 | if (node == NULL)
19 | return;
20 |
21 | printInorder(node->left);
22 | cout << node->data << " ";
23 | printInorder(node->right);
24 | }
25 |
26 | int main()
27 | {
28 | struct Node *root = new Node(1);
29 | root->left = new Node(2);
30 | root->right->left = new Node(3);
31 | root->left->left = new Node(4);
32 | root->left->right = new Node(5);
33 |
34 | cout << "\nInorder traversal of binary tree is \n";
35 | printInorder(root);
36 |
37 |
38 | return 0;
39 | }
40 |
--------------------------------------------------------------------------------
/Graphs1/DFS.cpp:
--------------------------------------------------------------------------------
1 |
2 | public:
3 | Graph(int V);
4 | void addEdge(int src, int dest);
5 | void DFS(int vertex);
6 | };
7 |
8 | // Initialize graph
9 | Graph::Graph(int vertices) {
10 | numVertices = vertices;
11 | adjLists = new list[vertices];
12 | visited = new bool[vertices];
13 | }
14 |
15 | // Add edges
16 | void Graph::addEdge(int src, int dest) {
17 | adjLists[src].push_front(dest);
18 | }
19 |
20 | // DFS algorithm
21 | void Graph::DFS(int vertex) {
22 | visited[vertex] = true;
23 | list adjList = adjLists[vertex];
24 |
25 | cout << vertex << " ";
26 |
27 | list::iterator i;
28 | for (i = adjList.begin(); i != adjList.end(); ++i)
29 | if (!visited[*i])
30 | DFS(*i);
31 | }
32 |
33 | int main() {
34 | Graph g(4);
35 | g.addEdge(0, 1);
36 | g.addEdge(0, 2);
37 | g.addEdge(1, 2);
38 | g.addEdge(2, 3);
39 |
40 | g.DFS(2);
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/Trees/Preorder.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 |
6 | struct Node
7 | {
8 | int data;
9 | struct Node* left, *right;
10 | Node(int data)
11 | {
12 | this->data = data;
13 | left = right = NULL;
14 | }
15 | };
16 |
17 |
18 | void printPreorder(struct Node* node)
19 | {
20 | if (node == NULL)
21 | return;
22 |
23 | cout << node->data << " ";
24 | printPreorder(node->left);
25 | printPreorder(node->right);
26 | }
27 |
28 | int main()
29 | {
30 | struct Node *root = new Node(1);
31 | root->left = new Node(2);
32 | root->right = new Node(3);
33 | root->right->left = new Node(3);
34 | root->left->left= new Node(4);
35 | root->left->right = new Node(5);
36 |
37 | cout << "\nPreorder traversal of binary tree is \n";
38 | printPreorder(root);
39 |
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/Assignment1/Power.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 | Find power of a number
11 | Send Feedback
12 | Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.
13 | Input format :
14 | Two integers x and n (separated by space)
15 | Output Format :
16 | x^n (i.e. x raise to the power n)
17 | Sample Input 1 :
18 | 3 4
19 | Sample Output 1 :
20 | 81
21 | Sample Input 2 :
22 | 2 5
23 | Sample Output 2 :
24 | 32
25 | */
26 |
27 |
28 | #include
29 |
30 | using namespace std;
31 | int power(int x, int n){
32 | if (n==0)
33 | {
34 | return 1;
35 | }
36 |
37 | return x*power(x, n-1);
38 |
39 |
40 | }
41 |
42 | int main( int argc , char ** argv )
43 | {
44 | ios_base::sync_with_stdio(false) ;
45 | cin.tie(NULL) ;
46 |
47 | int x, n;
48 | cin>>x>>n;
49 |
50 | cout << power(x,n) << '\n';
51 |
52 |
53 | return 0 ;
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/Binary_Search_Program:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main()
5 | {
6 | int count, i, arr[30], num, first, last, middle;
7 | cout<<"how many elements would you like to enter?:";
8 | cin>>count;
9 |
10 | for (i=0; i>arr[i];
14 | }
15 | cout<<"Enter the number that you want to search:";
16 | cin>>num;
17 | first = 0;
18 | last = count-1;
19 | middle = (first+last)/2;
20 | while (first <= last)
21 | {
22 | if(arr[middle] < num)
23 | {
24 | first = middle + 1;
25 |
26 | }
27 | else if(arr[middle] == num)
28 | {
29 | cout< last)
38 | {
39 | cout<
4 | #include
5 |
6 | #include "Matrix.hpp"
7 |
8 | class NeuralNetwork {
9 | private:
10 | int input_nodes;
11 | int hidden_nodes;
12 | int output_nodes;
13 | Matrix weights_ih;
14 | Matrix weights_ho;
15 | Matrix bias_h;
16 | Matrix bias_o;
17 |
18 | double learningRate = 0.1;
19 |
20 | public:
21 | NeuralNetwork(const NeuralNetwork &);
22 | NeuralNetwork(unsigned, unsigned, unsigned);
23 | NeuralNetwork();
24 |
25 | unsigned getInputNodes();
26 | unsigned getHiddenNodes();
27 | unsigned getOutputNodes();
28 |
29 | Matrix getWeightsIh();
30 | Matrix getWeightsHo();
31 |
32 | Matrix getHiddenBias();
33 | Matrix getOutputBias();
34 |
35 | void setLearningRate(double);
36 |
37 | void train(vector, vector);
38 | vector predict(vector);
39 | void mutate(functioncall);
40 |
41 | NeuralNetwork& copy();
42 |
43 | //Tests
44 | void print();
45 | };
--------------------------------------------------------------------------------
/Greedy/minabsdiff.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 |
7 | */
8 |
9 | /*
10 | PROBLEM STATEMENT
11 |
12 | Given an integer array A of size N, find and return the minimum absolute difference between
13 | any two elements in the array.
14 | We define the absolute difference between two elements ai, and aj (where i != j ) is |ai - aj|.
15 | Input format :
16 | Line 1 : Integer N, Array Size
17 | Line 2 : Array elements (separated by space)
18 | Output Format :
19 | Minimum difference
20 | */
21 |
22 | int minAbsoluteDiff(int arr[], int n) {
23 | int minimum = INT_MIN;
24 |
25 | sort(arr, arr+n);
26 |
27 | for (int i = 0; i < n-1; ++i)
28 | {
29 | int temp = arr[i+1]-arr[i];
30 | minimum = min(temp, minimum);
31 | }
32 |
33 | return minimum;
34 |
35 | }
36 |
37 |
38 | #include
39 |
40 | using namespace std;
41 |
42 |
43 | int main( int argc , char ** argv )
44 | {
45 | ios_base::sync_with_stdio(false) ;
46 | cin.tie(NULL) ;
47 |
48 |
49 |
50 |
51 | return 0 ;
52 |
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/String/Zalgo.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 |
7 | */
8 |
9 | /*
10 | PROBLEM STATEMENT
11 |
12 | */
13 |
14 | #include
15 | using namespace std;
16 |
17 | typedef long long ll;
18 | typedef unordered_map umapii;
19 | typedef unordered_map umapib;
20 | typedef unordered_map umapsi;
21 | typedef unordered_map umapss;
22 | typedef map mapsi;
23 | typedef map, int> mappiii;
24 | typedef map mapii;
25 | typedef pair pii;
26 | typedef pair pll;
27 | typedef unordered_set useti;
28 |
29 | #define uset unordered_set
30 | #define it iterator
31 | #define mp make_pair
32 | #define pb push_back
33 | #define all(x) (x).begin(), (x).end()
34 | #define f first
35 | #define s second
36 | #define MOD 1000000007
37 |
38 |
39 | int main( int argc , char ** argv )
40 | {
41 | ios_base::sync_with_stdio(false) ;
42 | cin.tie(NULL) ;
43 |
44 |
45 |
46 |
47 |
48 |
49 | return 0 ;
50 |
51 |
52 |
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/Bit Manipulation/Unset.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 | */
7 | /*
8 | PROBLEM STATEMENT
9 | You are given two integers N and i. You need to make ith bit of binary representation of N to 0
10 | and return the updated N.
11 | Counting of bits start from 0 from right to left.
12 | Input Format :
13 | Two integers N and i (separated by space)
14 | Output Format :
15 | Updated N
16 | Sample Input 1 :
17 | 7 2
18 | Sample Output 1 :
19 | 3
20 | Sample Input 2 :
21 | 12 1
22 | Sample Output 2 :
23 | 12
24 | */
25 |
26 | #include
27 |
28 | using namespace std;
29 |
30 | int turnOffIthBit(int n, int i){
31 | // k must be greater than 0
32 | if (i < 0) return n;
33 |
34 | // Do & of n with a number with all set bits except
35 | // the k'th bit
36 | return (n & ~(1 << (i)));
37 |
38 | }
39 |
40 |
41 | int main( int argc , char ** argv )
42 | {
43 | ios_base::sync_with_stdio(false) ;
44 | cin.tie(NULL) ;
45 |
46 | int n, i;
47 |
48 | cin >> n >> i;
49 |
50 | cout<< turnOffIthBit(n, i) <
11 | using namespace std;
12 |
13 |
14 | void printSolution(int** solution,int n){
15 | for(int i=0;i=n || x<0 || y>=n || y<0 || maze[x][y] ==0 || solution[x][y] ==1){
32 | return;
33 | }
34 | solution[x][y] = 1;
35 | mazeHelp(maze,n,solution,x-1,y);
36 | mazeHelp(maze,n,solution,x+1,y);
37 | mazeHelp(maze,n,solution,x,y-1);
38 | mazeHelp(maze,n,solution,x,y+1);
39 | solution[x][y] = 0;
40 | }
41 | void ratInAMaze(int maze[][20], int n){
42 |
43 | int** solution = new int*[n];
44 | for(int i=0;i
25 |
26 | using namespace std;
27 | long staircase(int n){
28 | long* arr = new long[n+1];
29 | arr[0] = 0;
30 | arr[1] = 1;
31 | arr[2] = 2;
32 | arr[3] = 4;
33 |
34 | for (int i = 4; i < n+1; ++i)
35 | {
36 | arr[i] = arr[i-1] + arr[i-2] + arr[i-3];
37 | }
38 |
39 | return arr[n];
40 |
41 | }
42 |
43 | int main( int argc , char ** argv )
44 | {
45 | ios_base::sync_with_stdio(false) ;
46 | cin.tie(NULL) ;
47 |
48 | int n;
49 | cin >> n ;
50 | cout << staircase(n) << endl;
51 |
52 |
53 | return 0 ;
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/fileupload/urls.py:
--------------------------------------------------------------------------------
1 | """fileupload URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path
18 | from distribution import views
19 | from django.conf import settings
20 | from django.conf.urls.static import static
21 | urlpatterns = [
22 | path('admin/', admin.site.urls),
23 | path('', views.Home.as_view(), name='home'),
24 | path('upload/', views.upload, name='upload'),
25 |
26 |
27 | ]
28 | if settings.DEBUG:
29 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
--------------------------------------------------------------------------------
/Language-Tools/Find-the-Unique-Element.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 |
11 | Given an integer array of size 2N + 1. In this given array, N numbers are present twice and one number
12 | is present only once in the array.You need to find and return that number which is unique in the array.
13 | Note : Given array will always contain odd number of elements.
14 |
15 | */
16 |
17 |
18 | #include
19 |
20 | using namespace std;
21 |
22 | int FindUnique(int arr[], int size){
23 | unordered_map m1;
24 |
25 | for (int i = 0; i < size; ++i)
26 | {
27 | m1[arr[i]]++;
28 | }
29 |
30 | for (int i = 0; i < size; ++i)
31 | {
32 | if (m1[arr[i]]==1)
33 | {
34 | return arr[i];
35 | }
36 | }
37 |
38 | return 0;
39 |
40 |
41 | }
42 |
43 | int main( int argc , char ** argv )
44 | {
45 | ios_base::sync_with_stdio(false) ;
46 | cin.tie(NULL) ;
47 |
48 | int size;
49 |
50 | cin>>size;
51 | int *input=new int[1+size];
52 |
53 | for(int i=0;i>input[i];
55 |
56 | cout<> threeSum(vector& nums) {
12 | set> ans;
13 | int n= nums.size();
14 | if(n <3)
15 | return {};
16 |
17 | sort(nums.begin(), nums.end()); //for using two pointers technique
18 |
19 | for(int i=0; i0 && nums[i] == nums[i-1])
23 | continue;
24 | int start = i+1, end= n-1;
25 | while(start < end){
26 | int sum = nums[i] + nums[start]+ nums[end];
27 | if(sum == 0)
28 | { ans.insert({nums[i],nums[start], nums[end]}); start +=1;}
29 |
30 | else if(sum > 0)
31 | end -=1;
32 | else
33 | start +=1;
34 |
35 | }
36 | }
37 |
38 | vector> yo;
39 | for(auto i= ans.begin(); i != ans.end(); i++)
40 | yo.push_back(*i);
41 | return yo;
42 | }
43 | };
44 |
--------------------------------------------------------------------------------
/Language-Tools/Different-names.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | In Little Flowers Public School, there are many students with same first names.
10 | You are given a task to find the students with same names.
11 | You will be given a string comprising of all the names of students and you have
12 | to tell the name and count of those students having same. If all the names are unique, print -1 instead.
13 | Note: We don't have to mention names whose frequency is 1.
14 |
15 | */
16 |
17 | #include
18 |
19 | using namespace std;
20 |
21 |
22 | int main( int argc , char ** argv )
23 | {
24 | ios_base::sync_with_stdio(false) ;
25 | cin.tie(NULL) ;
26 |
27 | string names;
28 | getline(cin, names);
29 | //cout << names << '\n';
30 |
31 | stringstream iss(names);
32 |
33 | unordered_map m1;
34 | string temp;
35 |
36 | while(iss>>temp){
37 | m1[temp]++;
38 | }
39 |
40 | unordered_map :: iterator it=m1.begin();
41 | int count = 0;
42 | for (it; it != m1.end(); ++it)
43 | {
44 | if(it->second>1){
45 | cout << it->first<<" "<< it->second << '\n';
46 | count++;
47 | }
48 | }
49 | if (count == 0)
50 | {
51 | cout << -1 << '\n';
52 | }
53 |
54 | return 0 ;
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/Language-Tools/Repeat-and-Missing-Number -Array.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 |
11 | You are given a read only array of n integers from 1 to n.
12 |
13 | Each integer appears exactly once except A which appears twice and B which is missing.
14 |
15 | Return A and B.
16 |
17 | Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
18 |
19 | Note that in your output A should precede B.
20 |
21 |
22 |
23 |
24 | */
25 |
26 |
27 |
28 | #include
29 |
30 | using namespace std;
31 | vector Solution::repeatedNumber(const vector &A) {
32 | long long int len = A.size();
33 | long long int Sum_N = (len * (len+1) ) /2, Sum_NSq = (len * (len +1) *(2*len +1) )/6;
34 | long long int missingNumber=0, repeating=0;
35 |
36 | for(int i=0;i ans;
44 | ans.push_back(repeating);
45 | ans.push_back(missingNumber);
46 | return ans;
47 |
48 |
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Graphs1/Prims MST.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | vector taken;
5 | vector > > AdjList;
6 | priority_queue > pq; //Max-Heap in C++ STL
7 |
8 | void process(int vtx)
9 | {
10 | taken[vtx]=1;
11 | for(int j=1; j<(int)AdjList[vtx].size(); j++)
12 | {
13 | pair v=AdjList[vtx][j];
14 | if(!taken[v.first]) pq.push(make_pair(-v.second,-v.first));
15 | }
16 | }
17 |
18 | int main()
19 | {
20 | cout<<"Enter the number of vertices: ";
21 | int V;
22 | cin>>V;
23 | vector > temp(1,make_pair(-1,-1));
24 | for(int i=0;i>E;
28 | cout<<"Enter the edges with their weights: ";
29 | for(int i=0; i>u>>v>>w;
33 | AdjList[u].push_back(make_pair(v,w));
34 | AdjList[v].push_back(make_pair(u,w));
35 | }
36 | taken.assign(V,0);
37 | int weight=0;
38 |
39 | process(0);
40 | while(!pq.empty())
41 | {
42 | pair p=pq.top();
43 | pq.pop();
44 | int u=-p.second;
45 | int w=-p.first;
46 |
47 | if(!taken[u])
48 | weight+=w, process(u);
49 | }
50 |
51 | cout<<"The weight of the MST is: "<
29 |
30 | using namespace std;
31 |
32 | int getMaxMoney(int arr[], int n){
33 | std::vector dp(n, 0);
34 |
35 | if (n==1)
36 | {
37 | return arr[0];
38 | }
39 | if (n==2)
40 | {
41 | return max(arr[0], arr[1]);
42 | }
43 |
44 | dp[0] = arr[0];
45 | dp[1] = max(arr[1], arr[0]);
46 |
47 | for (int i = 2; i < n; ++i)
48 | {
49 | dp[i] =max(dp[i-1], arr[i] + dp[i-2]);
50 | }
51 |
52 | return *max_element(dp.begin(), dp.end());
53 |
54 | }
55 |
56 | int main( int argc , char ** argv )
57 | {
58 | ios_base::sync_with_stdio(false) ;
59 | cin.tie(NULL) ;
60 |
61 | int n;
62 | cin >> n;
63 | int arr[10000];
64 | for(int i=0; i> arr[i];
66 | }
67 | cout << getMaxMoney(arr, n);
68 |
69 |
70 |
71 | return 0 ;
72 |
73 |
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/Language-Tools/Duplicateinarray.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 | Given an array of integers of size n which contains numbers from 0 to n - 2. Each number is present at least once. That is, if n = 5, numbers from 0 to 3 is present in the given array at least once and one number is present twice. You need to find and return that duplicate number present in the array.
11 | Assume, duplicate number is always present in the array.
12 | Input format :
13 | Line 1 : Size of input array
14 | Line 2 : Array elements (separated by space)
15 | Output Format :
16 | Duplicate element
17 |
18 | */
19 |
20 |
21 | #include
22 |
23 | using namespace std;
24 | int MissingNumber(int arr[], int size){
25 | unordered_map m1;
26 | for (int i = 0; i < size; ++i)
27 | {
28 | m1[arr[i]]++;
29 | }
30 |
31 | for (int i = 0; i < size; ++i)
32 | {
33 | if (m1[arr[i]] == 2)
34 | {
35 | return arr[i];
36 | }
37 | }
38 |
39 | return -1;
40 | }
41 |
42 |
43 | int main( int argc , char ** argv )
44 | {
45 | ios_base::sync_with_stdio(false) ;
46 | cin.tie(NULL) ;
47 | int size;
48 | cin >> size;
49 | int *input = new int[1 + size];
50 |
51 | for(int i = 0; i < size; i++)
52 | cin >> input[i];
53 |
54 | cout << MissingNumber(input, size);
55 |
56 | delete [] input;
57 |
58 | return 0;
59 |
60 |
61 |
62 | return 0 ;
63 |
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/Language-Tools/3-zero-sum.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 | /*
8 | PROBLEM STATEMENT
9 | Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?
10 | Find all unique triplets in the array which gives the sum of zero.
11 |
12 | Note:
13 |
14 | Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
15 | The solution set must not contain duplicate triplets. For example, given array S = {-1 0 1 2 -1 -4}, A solution set is:
16 | (-1, 0, 1)
17 | (-1, -1, 2)
18 |
19 | */
20 |
21 | #include
22 |
23 | using namespace std;
24 |
25 | vector > threeSum(vector &A) {
26 | sort(A.begin(), A.end());
27 | int n = A.size();
28 | vector > result;
29 | int c = 0;
30 | for (auto i = 0; i0 && A[i]==A[i-1])
34 | continue;
35 |
36 | while(l temp = {A[i], A[l], A[r]};
42 | int s = result.size();
43 | if(s>0 && result[s-1][0]==temp[0] && result[s-1][1]==temp[1] && result[s-1][2]==temp[2]);
44 | else
45 | result.push_back(temp);
46 | ++l; --r;
47 | }
48 | else if(sum>0)
49 | --r;
50 | else
51 | ++l;
52 | }
53 | }
54 | return result;
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/Number Theory/prime.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 |
7 | */
8 |
9 | /*
10 | PROBLEM STATEMENT
11 |
12 | */
13 |
14 | #include
15 | using namespace std;
16 |
17 | typedef long long ll;
18 | typedef unordered_map umapii;
19 | typedef unordered_map umapib;
20 | typedef unordered_map umapsi;
21 | typedef unordered_map umapss;
22 | typedef map mapsi;
23 | typedef map, int> mappiii;
24 | typedef map mapii;
25 | typedef pair pii;
26 | typedef pair pll;
27 | typedef unordered_set useti;
28 |
29 | #define uset unordered_set
30 | #define it iterator
31 | #define mp make_pair
32 | #define pb push_back
33 | #define all(x) (x).begin(), (x).end()
34 | #define f first
35 | #define s second
36 | #define MOD 1000000007
37 |
38 |
39 | int main( int argc , char ** argv )
40 | {
41 | ios_base::sync_with_stdio(false) ;
42 | cin.tie(NULL) ;
43 |
44 | int n;
45 | cin>>n;
46 | int count = 0;
47 |
48 | if (n>=2)
49 | {
50 | count++;
51 | }
52 | if (n>=3)
53 | {
54 | count++;
55 | }
56 |
57 | //cout << n << '\n';
58 | for (int i = 2; i <= n; ++i)
59 | {
60 | int flag = 0;
61 | for (int j = 2; j*j <= i; ++j)
62 | {
63 | if (i%j==0)
64 | {
65 | flag = 0;
66 | break;
67 | }else{
68 | flag = 1;
69 | }
70 |
71 | }
72 | if (flag == 1)
73 | {
74 | count++;
75 | }
76 | }
77 |
78 | cout <u,vectorv)
21 | {
22 | //Creating matrix
23 | int** matrix = new int*[n+1];
24 |
25 | for(int i=0;i<=n;i++){
26 | matrix[i] = new int[n+1];
27 |
28 | for(int j=0;j<=n;j++){
29 | matrix[i][j]=0;
30 | }
31 |
32 | }
33 |
34 | for(int i=0;i
13 |
14 | using namespace std;
15 |
16 | int board[11][11];
17 |
18 | bool isPossible(int n,int row,int col){
19 |
20 | // Same Column
21 | for(int i=row-1;i>=0;i--){
22 | if(board[i][col] == 1){
23 | return false;
24 | }
25 | }
26 | //Upper Left Diagonal
27 | for(int i=row-1,j=col-1;i>=0 && j>=0 ; i--,j--){
28 | if(board[i][j] ==1){
29 | return false;
30 | }
31 | }
32 |
33 | // Upper Right Diagonal
34 |
35 | for(int i=row-1,j=col+1;i>=0 && j
33 |
34 | using namespace std;
35 |
36 | int knapSack(int W, int wt[], int val[], int n)
37 | {
38 | int i, w;
39 | int K[n+1][W+1];
40 |
41 | // Build table K[][] in bottom up manner
42 | for (i = 0; i <= n; i++)
43 | {
44 | for (w = 0; w <= W; w++)
45 | {
46 | if (i==0 || w==0)
47 | K[i][w] = 0;
48 | else if (wt[i-1] <= w)
49 | K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]);
50 | else
51 | K[i][w] = K[i-1][w];
52 | }
53 | }
54 |
55 | return K[n][W];
56 | }
57 |
58 | int knapsack(int* weights, int* values, int n, int maxWeight){
59 |
60 | return knapSack(maxWeight, weights, values, n);
61 |
62 |
63 | }
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/adhoc problems/Circularlist.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 | You are given a circular list of students as follows:
11 | 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11
12 | This list is circular, means that 11 will follow 0 again. You will be given the student number ‘i’ and
13 | some position ‘p’. You will have to tell that if the list will start from (i+1)th student,
14 | then which student will be at pth position.
15 | Input Format:
16 | First line will have an integer ‘t’, denoting the number of test cases.
17 | Next line will have two space separated integers denoting the value of ‘i’ and ‘p’ respectively.
18 | Output Format:
19 | Print ‘t’ lines containing single integer denoting the student number.
20 | Constraints:
21 | 1 <= t <= 10^5
22 | 0 <= i <= 11
23 | 1 <= p <= 12
24 | Sample Input:
25 | 2
26 | 2 3
27 | 5 8
28 | Sample Output:
29 | 5
30 | 1
31 | Explanation:
32 | First, list will start at 3. 3 -> 4 -> 5. Hence, 5 will be at third position.
33 | Second, list will start at 6. 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 0 -> 1. Hence, 1 will be at 8th
34 | position.
35 | */
36 |
37 |
38 | #include
39 |
40 | using namespace std;
41 |
42 | int go(int i, int p){
43 | int ans = (i+p)%12
44 | return ans;
45 | }
46 |
47 |
48 | int main( int argc , char ** argv )
49 | {
50 | ios_base::sync_with_stdio(false) ;
51 | cin.tie(NULL) ;
52 |
53 | int t;
54 | cin>>t;
55 |
56 | while(t--){
57 | int i, p;
58 | cin>>i>>p;
59 |
60 | cout << go(i, p) << '\n';
61 | }
62 |
63 |
64 | return 0 ;
65 |
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/Prerequisites/marbles.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Gourav Singh
4 | https://www.linkedin.com/in/gouravsingh2580/
5 |
6 |
7 | */
8 |
9 |
10 | #include
11 |
12 | using namespace std;
13 |
14 |
15 | int main( int argc , char ** argv )
16 | {
17 | ios_base::sync_with_stdio(false) ;
18 | cin.tie(NULL) ;
19 |
20 | int n,sum;
21 |
22 | cin>> n>>sum;
23 |
24 | int* arr = new int[n];
25 | for (int i = 0; i < n; ++i)
26 | {
27 | cin>>arr[i];
28 | }
29 |
30 | int start=0;
31 | int end=0;
32 | int tempsum=arr[end];
33 |
34 | while(1){
35 | //tempsum=tempsum+arr[end];
36 | cout << "temp"<sum)
61 | { if (startend){
66 | end++;
67 | tempsum = arr[end];
68 | }
69 | continue;
70 | }else{
71 | cout << "false" << '\n';
72 | return 0;
73 | }
74 |
75 | }else if (start == n-1)
76 | {
77 | cout << "false" << '\n';
78 | return 0;
79 | }
80 |
81 |
82 |
83 |
84 | }
85 |
86 |
87 |
88 |
89 |
90 |
91 | return 0 ;
92 |
93 |
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/Language-Tools/Pairsumtozero.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Name: Mehul Chaturvedi
4 | IIT-Guwahati
5 |
6 | */
7 |
8 | /*
9 | PROBLEM STATEMENT
10 | Given a random integer array A of size N. Find and print the pair of elements in the array which sum to 0.
11 | Array A can contain duplicate elements.
12 | While printing a pair, print the smaller element first.
13 | That is, if a valid pair is (6, -6) print "-6 6". There is no constraint that out of 5 pairs which have to be printed in 1st line.
14 | You can print pairs in any order, just be careful about the order of elements in a pair.
15 |
16 | */
17 |
18 | #include
19 |
20 | using namespace std;
21 |
22 | void PairSum(int *input, int n) {
23 | unordered_map m1;
24 | for (int i = 0; i < n; ++i)
25 | {
26 | if(m1[0-input[i]]==0){
27 | m1[input[i]]++;
28 |
29 | }else{
30 | m1[input[i]]++;
31 | }
32 | }
33 |
34 | unordered_map::iterator it=m1.begin();
35 | while(it!=m1.end()){
36 | int total = 0;
37 | int left = it->second;
38 | int right = m1[-it->first];
39 | total = left*right;
40 | while(total>0){
41 | cout << min(it->first, -it->first)<<" "<< max(it->first, -it->first) << '\n';
42 | total--;
43 | }
44 | m1[it->first]=0;
45 | m1[-it->first]=0;
46 | it++;
47 |
48 | }
49 |
50 | }
51 |
52 | int main( int argc , char ** argv )
53 | {
54 | ios_base::sync_with_stdio(false) ;
55 | cin.tie(NULL) ;
56 |
57 | int n;
58 | int arr[100000];
59 | cin>>n;
60 | for(int i=0; i>arr[i];
63 | }
64 | PairSum(arr, n);
65 | return 0;
66 |
67 |
68 |
69 | return 0 ;
70 |
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Competitive Programming 🌟
2 |
3 | ## Topics in the Repo
4 |
5 | - ## `Advanced Graphs`
6 | 
7 |
8 | - Airport2.cpp
9 | - Airportwrong.cpp
10 | - Bottom.cpp
11 | - Connectedhorses.cpp
12 | - Dominos.cpp
13 | - Kingdom.cpp
14 | - Matrix.cpp
15 | - Monk.cpp
16 | - Newyear.cpp
17 | - Permutationsswap.cpp
18 | - Test.txt
19 | - a.out
20 |
21 | - ## `Assignment1`
22 | 
23 |
24 | - Collecting the balls.cpp
25 | - Power.cpp
26 | - Sortingskills.cpp
27 | - Test.txt
28 | - a.out
29 |
30 | - ## `Backtracking`
31 | 
32 |
33 | - Crossword.cpp
34 | - Fillthematrix.cpp
35 | - Nqueens.cpp
36 | - Rateinamaze.cpp
37 | - Test.txt
38 | - a.out
39 | - check.cpp
40 |
41 | - ## `Bit Manipulation`
42 | 
43 |
44 | - Unset.cpp
45 |
46 | - ## `DP1(Very important)`
47 | 
48 |
49 | - Adjacentbit
50 | - Adjacentbit.cpp
51 | - Allzeroes
52 | - Allzeroes.cpp
53 | - AlphaCode-Question.cpp
54 | - Boredom.cpp
55 | - Hasanandtrip.cpp
56 | - Loot.cpp
57 | - Maximumsum.cpp
58 | - Mergegrid.cpp
59 | - Royandcoin.cpp
60 | - Test.txt
61 | - Vanya and gcd
62 | - Vanya and gcd.cpp
63 | - a.out
64 | - angrychildren
65 | - angrychildren.cpp
66 | - coinchange.cpp
67 | - jonsnow.cpp
68 | - longestbitonicsubarray.cpp
69 | - minchoc.cpp
70 | - mincount.cpp
71 | - spreadsheet.cpp
72 | - staircase.cpp
73 |
--------------------------------------------------------------------------------
/DPandbitmasking/Mehta.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include