Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
4933de0
Merge pull request #1 from Haresh1204/main
ajitkumar1264 Sep 11, 2022
6848fff
new
Annex5061 Sep 14, 2022
269f8ad
Merge pull request #3 from Annex5061/main
ajitkumar1264 Sep 14, 2022
223b63e
Triangle
ShiroNek Sep 27, 2022
491e0c0
Merge pull request #4 from ShiroNek/main
ajitkumar1264 Sep 27, 2022
01c7f73
Bike helmet tilt
VISHNUGOVIND007 Sep 27, 2022
2c6f01e
Add files via upload
VISHNUGOVIND007 Sep 27, 2022
58e9fb1
Delete Binary search.dev
VISHNUGOVIND007 Sep 27, 2022
c22f7b0
Delete Bike helmet tilt.dev
VISHNUGOVIND007 Sep 27, 2022
61b08d4
Create Binary search
VISHNUGOVIND007 Sep 27, 2022
9352947
Bike helmet tilt
VISHNUGOVIND007 Sep 27, 2022
a364fe4
Merge pull request #5 from VISHNUGOVIND007/main
ajitkumar1264 Sep 27, 2022
6201201
1.cpp
Sep 27, 2022
a16dc8c
Merge pull request #6 from vxnshhh/main
ajitkumar1264 Sep 28, 2022
76ec1f1
Merge Sort
shrikant2233 Sep 28, 2022
fdbba03
Merge Sort
shrikant2233 Sep 28, 2022
19e43f2
Merge pull request #7 from shrikant2233/main
ajitkumar1264 Sep 28, 2022
3053f4d
Bucketsort
megha-vishwakarma Sep 28, 2022
104b422
Bucket Sort
megha-vishwakarma Sep 28, 2022
f1deb39
Add files via upload
790hanu Sep 28, 2022
3205cd1
Merge pull request #8 from megha-vishwakarma/main
ajitkumar1264 Sep 29, 2022
dd0047d
Merge pull request #9 from 790hanu/main
ajitkumar1264 Sep 29, 2022
8510b68
bubble sort
mrizky-kur Sep 30, 2022
6ff772e
Merge pull request #10 from mrizky-kur/main
ajitkumar1264 Sep 30, 2022
a9a4698
bubble_sort
yolandu19 Sep 30, 2022
4a907d9
feat: create new file
FerreiraWalter Sep 30, 2022
a29740c
Create tree.cpp
FerreiraWalter Sep 30, 2022
41d2947
Merge pull request #13 from FerreiraWalter/patch-2
ajitkumar1264 Sep 30, 2022
3a1e82e
Merge pull request #12 from FerreiraWalter/patch-1
ajitkumar1264 Sep 30, 2022
6054538
Merge pull request #11 from yolandu19/main
ajitkumar1264 Sep 30, 2022
45df29a
CONTRIBUTING file
ajitkumar1264 Sep 30, 2022
57a8868
SortingusingSort.java
ShalabhDevliyal Sep 30, 2022
53afe23
Multiply_two_matrices
Ankit-gurjar Sep 30, 2022
53c9788
:fire: created the radix sort implementation in java
JatinBisht2308 Sep 30, 2022
50ae1ce
Create complex-string.java
arora1mayank Sep 30, 2022
863fb89
Subarray
tilak-codes Sep 30, 2022
6eb2362
Added mergeSort
Naman-pokhriyal Sep 30, 2022
310ad87
StudentDBMS.cpp
bhumika-ag Sep 30, 2022
d92b9ca
hacktoberfest event
malhar619 Sep 30, 2022
5bda76e
hacktoberfest event
malhar619 Sep 30, 2022
d4db1f1
Added a functional Knapsack program
iamvpbhaskar Sep 30, 2022
07b3630
Update and rename Knapsack.java to poi_dyn_str.cpp
malhar619 Sep 30, 2022
24b644d
add bubblesort algorithm with javascript
ariear Oct 1, 2022
cfc1e56
BinarySearch
samraj-freak Oct 1, 2022
2e8b2b1
bubblesort
ev1lclow3n Oct 1, 2022
71d1f9f
QuickSortAlgorithm
kaustubh589 Oct 1, 2022
6ce2297
Merge pull request #27 from kaustubh589/main
ajitkumar1264 Oct 1, 2022
9e38fa3
Merge pull request #26 from ev1lclow3n/main
ajitkumar1264 Oct 1, 2022
b04cb24
Merge pull request #25 from samraj-freak/main
ajitkumar1264 Oct 1, 2022
af14532
Merge pull request #24 from ariear/main
ajitkumar1264 Oct 1, 2022
8949858
Create LONGEST-INCREASING-SUBSEQUENCE.cpp
HARSH-VATS-6 Oct 1, 2022
8cd70e0
Merge pull request #28 from HARSH-VATS-6/main
ajitkumar1264 Oct 1, 2022
9fe2a0c
Merge pull request #23 from iamvpbhaskar/main
ajitkumar1264 Oct 1, 2022
43d4d10
Merge pull request #22 from malhar619/main
ajitkumar1264 Oct 1, 2022
2ec630a
Merge pull request #20 from bhumika-ag/main
ajitkumar1264 Oct 1, 2022
270e7f3
Merge pull request #19 from Naman-pokhriyal/namanPokhriyal
ajitkumar1264 Oct 1, 2022
e316d61
Merge pull request #18 from tilak-codes/main
ajitkumar1264 Oct 1, 2022
5f522d6
Merge pull request #17 from arora1mayank/main
ajitkumar1264 Oct 1, 2022
a11691f
Merge pull request #16 from JatinBisht2308/jatinbisht
ajitkumar1264 Oct 1, 2022
51c9311
Merge pull request #15 from Ankit-gurjar/main
ajitkumar1264 Oct 1, 2022
0feee38
Merge pull request #14 from ShalabhDevliyal/main
ajitkumar1264 Oct 1, 2022
d30ac6c
Count total number of occurances of a character algorithm
fabian-prog Oct 1, 2022
fca92e9
First and last occurance binary search
fabian-prog Oct 1, 2022
bd28e52
Create matrix.java
novanazizr Oct 1, 2022
a72a204
Create Sedgwik.cpp
Shanonbaker Oct 1, 2022
89248d8
Add files via upload
dharmanshu1921 Oct 1, 2022
42539b1
Add files via upload
itssubhamroy23 Oct 1, 2022
1f11c8f
Update README.md
yashsinha2512 Oct 1, 2022
25a5e7f
minimum extraction
tilak-codes Oct 1, 2022
130c37d
Sieve_algorithm
Asmit-Kumar0 Oct 1, 2022
21ab0b8
chore: organize the folder structure
RavenColEvol Oct 1, 2022
1c96e06
hactoberfest-2022
Asmit-Kumar0 Oct 1, 2022
ea54ded
StringIntro
anurag-compile Oct 1, 2022
ec9a639
hactoberfest-2022
bhattji007 Oct 1, 2022
60790f1
add get provider name algorithm
ariear Oct 1, 2022
d048bc4
Transpose_of_Matrix
dhirenkokal Oct 1, 2022
e1be6ae
Determinant_of_Matrix
dhirenkokal Oct 1, 2022
315ddce
Hashing
palaknaugriya Oct 1, 2022
1b68d62
Merge pull request #45 from palaknaugriya/main
ajitkumar1264 Oct 1, 2022
1b752de
Merge pull request #44 from dhirenkokal/main
ajitkumar1264 Oct 1, 2022
5646327
Merge pull request #43 from ariear/main
ajitkumar1264 Oct 1, 2022
412a92c
Merge pull request #42 from bhattji007/main
ajitkumar1264 Oct 1, 2022
0f46c6c
Merge pull request #41 from anurag-compile/main
ajitkumar1264 Oct 1, 2022
061c630
Create Search_an_element_in_a_sorted_and_rotated_Array.cpp
abhishek2384 Oct 1, 2022
0f00026
Merge pull request #40 from yashsinha2512/main
ajitkumar1264 Oct 1, 2022
252f662
Merge pull request #39 from RavenColEvol/main
ajitkumar1264 Oct 1, 2022
d847a67
Merge pull request #46 from abhishek2384/main
ajitkumar1264 Oct 1, 2022
d0aedb9
Merge pull request #38 from Asmit-Kumar0/main
ajitkumar1264 Oct 1, 2022
8eb107d
Merge pull request #37 from tilak-codes/main
ajitkumar1264 Oct 1, 2022
3cdb144
add sudoku solver
Sayam06 Oct 1, 2022
9fa945f
Merge pull request #35 from Haresh1204/main
ajitkumar1264 Oct 1, 2022
fc93d99
Merge pull request #47 from Sayam06/sudoku
ajitkumar1264 Oct 1, 2022
9cb5aed
Merge pull request #34 from itssubhamroy23/main
ajitkumar1264 Oct 1, 2022
8092771
Merge pull request #32 from dharmanshu1921/main
ajitkumar1264 Oct 1, 2022
85da306
SortinganArray
Shakshi2822 Oct 1, 2022
d64d14e
add: selection sort algo for jsc
RavenColEvol Oct 1, 2022
ca3b60d
Maximum of two number
dipesh88 Oct 1, 2022
a45b1e5
Armstrong number
Shakshi2822 Oct 1, 2022
2afe7e0
chore: organize files and update readme
RavenColEvol Oct 1, 2022
420d9e3
Merge pull request #51 from dipesh88/main
ajitkumar1264 Oct 1, 2022
fab4303
Merge pull request #50 from RavenColEvol/organize-note
ajitkumar1264 Oct 1, 2022
7219f18
Maximum 3 Numbers
dipesh88 Oct 1, 2022
2e929d7
activity_selection
aayushbarmecha Oct 1, 2022
8f747cb
Strings
dipesh88 Oct 1, 2022
17ec428
Merge pull request #31 from Shanonbaker/main
ajitkumar1264 Oct 1, 2022
8bfeda4
Binary to Decimal
dipesh88 Oct 1, 2022
dcca9b4
Merge pull request #48 from Alia6922/main
ajitkumar1264 Oct 1, 2022
c6df6f4
Add files via upload
Rishabhjain2002 Oct 1, 2022
38ddf2d
Merge pull request #30 from novanazizr/main
ajitkumar1264 Oct 1, 2022
bfb1b2b
Merge pull request #29 from fabian-prog/main
ajitkumar1264 Oct 1, 2022
acb8685
adjacency_list
aayushbarmecha Oct 1, 2022
a9079af
Leap year
dipesh88 Oct 1, 2022
b1d13bd
Add files via upload
aayushbarmecha Oct 1, 2022
bbda50c
Delete adjacency_list.cpp
aayushbarmecha Oct 1, 2022
89b325c
Alphabets
dipesh88 Oct 1, 2022
c198b2a
Hactoberfest-2022
Rishabhjain2002 Oct 1, 2022
0c6b2d6
Merge branch 'ajitkumar1264:main' into main
dipesh88 Oct 1, 2022
c9fce49
flyod_marshall
aayushbarmecha Oct 1, 2022
d5903fa
System Shut Down
dipesh88 Oct 1, 2022
837f852
hactoberfest-2022
aayushbarmecha Oct 1, 2022
464cf7b
hactoberfest-2022
Asmit-Kumar0 Oct 1, 2022
0d104d8
karatsuba
aayushbarmecha Oct 1, 2022
67a2892
Delete karatsuba.cpp
aayushbarmecha Oct 1, 2022
5d38ee8
Delete adjacency_matrix.cpp
aayushbarmecha Oct 1, 2022
cf14dd6
kruskal
aayushbarmecha Oct 1, 2022
f792b78
max_subarray
aayushbarmecha Oct 1, 2022
2051a2e
Create Quick_Sort.cpp
BlackBolt2003 Oct 1, 2022
76b6fcb
C# square root validator
JVisuri1 Oct 1, 2022
f5657b0
C# radian conversion algorithm
JVisuri1 Oct 1, 2022
ad33c45
Circular Queue In java
Parth013 Oct 1, 2022
69d57cd
Remove dublicate file
JVisuri1 Oct 1, 2022
c05f94a
Create dataManipulation.java
Samyak2000 Oct 1, 2022
7c70aeb
Singly Linked List
VarunBhattacharya Oct 1, 2022
d15292a
Create Kadane.cpp
prakhar-da-gama Oct 1, 2022
cca22cd
Fibonacci series
Yash-Agarwal1708 Oct 1, 2022
97b0792
add : binary search js
ariear Oct 1, 2022
b8ee51a
readme
suraj-s13 Oct 1, 2022
192e042
Rename readme to readme.md
suraj-s13 Oct 1, 2022
94f84a5
Update readme.md
suraj-s13 Oct 1, 2022
bef01b0
Create linkedListCycle.cpp
Rsr0 Oct 1, 2022
e6926d4
CODE
suraj-s13 Oct 1, 2022
5f970c2
Update and rename singlelinkedlist.c to singlelinkedlist.cpp
suraj-s13 Oct 1, 2022
7b6186b
Update readme.md
suraj-s13 Oct 1, 2022
9595105
ReverseOfArray
Himanshu-Gupta2001 Oct 1, 2022
15acc86
Add files via upload
yusmnn Oct 1, 2022
090dfa5
Create wildcardmatching.cpp
mansi0703 Oct 1, 2022
08a244f
Created snake-game
megha-vishwakarma Oct 1, 2022
ada3c62
created basic.py
AdityaWadkar Oct 1, 2022
51290da
Merge pull request #74 from AdityaWadkar/main
ajitkumar1264 Oct 1, 2022
a5366ad
Merge pull request #71 from mansi0703/main
ajitkumar1264 Oct 1, 2022
2ab9785
Merge pull request #72 from megha-vishwakarma/main
ajitkumar1264 Oct 1, 2022
ce8561a
Merge pull request #70 from yusmnn/main
ajitkumar1264 Oct 1, 2022
6194830
Merge pull request #69 from Himanshu-Gupta2001/main
ajitkumar1264 Oct 1, 2022
bff26a8
Merge pull request #68 from suraj-s13/SingleLinkedList
ajitkumar1264 Oct 1, 2022
b99ac63
Merge pull request #67 from Rsr0/main
ajitkumar1264 Oct 1, 2022
0328b57
Merge pull request #66 from ariear/main
ajitkumar1264 Oct 1, 2022
7ba539a
Merge pull request #65 from Yash-Agarwal1708/main
ajitkumar1264 Oct 1, 2022
b734b1e
Merge pull request #64 from prakhar-da-gama/main
ajitkumar1264 Oct 1, 2022
d418733
added kadane's algorithm code
skgx Oct 1, 2022
f6e33c0
Merge pull request #63 from VarunBhattacharya/main
ajitkumar1264 Oct 1, 2022
536c233
Merge pull request #61 from Samyak2000/main
ajitkumar1264 Oct 1, 2022
f2d205f
Merge pull request #75 from skgx/main
ajitkumar1264 Oct 1, 2022
1065cd1
Merge pull request #60 from JVisuri1/radian_algorithms
ajitkumar1264 Oct 1, 2022
6f3a86a
Merge pull request #59 from Parth013/main
ajitkumar1264 Oct 1, 2022
0b161dd
Merge pull request #57 from BlackBolt2003/main
ajitkumar1264 Oct 1, 2022
2df4825
Create nqueens.cpp
mansi0703 Oct 1, 2022
2a7cf5b
Merge pull request #56 from Asmit-Kumar0/main
ajitkumar1264 Oct 1, 2022
99a1778
Merge pull request #55 from Rishabhjain2002/main
ajitkumar1264 Oct 1, 2022
cd69604
Merge pull request #76 from mansi0703/patch-1
ajitkumar1264 Oct 1, 2022
46d7d21
Merge pull request #54 from dipesh88/main
ajitkumar1264 Oct 1, 2022
0db599a
Create ratInAMaze.cpp
mansi0703 Oct 1, 2022
1904030
Merge pull request #53 from aayushbarmecha/main
ajitkumar1264 Oct 1, 2022
857d410
hacktoberfest-2022
Namgup001 Oct 1, 2022
9a57802
web-scrapping using request
nandocoeg Oct 1, 2022
c49a21d
hacktoberfest-2022
Namgup001 Oct 1, 2022
b5597d8
Create 4sum.cpp
mansi0703 Oct 1, 2022
24d8adf
hacktoberfest-2022
Namgup001 Oct 1, 2022
3e68127
Merge pull request #80 from mansi0703/patch-3
ajitkumar1264 Oct 1, 2022
0b4ef8a
Merge pull request #79 from nandocoeg/main
ajitkumar1264 Oct 1, 2022
929e74a
Merge pull request #78 from Namgup001/main
ajitkumar1264 Oct 1, 2022
65e3126
Merge pull request #77 from mansi0703/patch-2
ajitkumar1264 Oct 1, 2022
82ab8b7
Create binary_conversions1.c
batrakeshav10 Oct 1, 2022
f62f2fe
Update 4Sum.cpp
batrakeshav10 Oct 1, 2022
5524cb2
Update Permutations in string.cpp
batrakeshav10 Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions 4Sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Question-

// Suppose we have an array of numbers. It stores n integers, there are four elements a, b, c and d in the array. We have another target value, such that a + b + c + d = target. Find all unique quadruplets in the array which satisfies the situation. So if the array is like [-1,0,1,2,0,-2] and target is 0, then the result will be [[-1, 0, 0, 1],[-2, -1, 1, 2], [-2, 0, 0, 2]]
// Input-
// [1,0,-1,0,-2,2]
// 0
// Output-
// [[1,2,-1,-2],[0,2,0,-2],[0,1,0,-1]]



#include <bits/stdc++.h>
using namespace std;


class Solution {
public:
void addAll(vector < vector <int> >& res, vector < vector <int> >& temp){
for(int i = 0; i < temp.size(); i++)res.push_back(temp[i]);
}
vector<vector<int>> fourSum(vector<int>& nums, int target) {
sort(nums.begin(), nums.end());
return kSum(nums, 0, 4, target);
}
vector < vector <int> > kSum(vector <int>& arr, int start, int k, int target){
vector < vector <int> > res;
if(k == 2){
int left = start;
int right = arr.size() - 1;
vector <int> temp(2);
while(left < right){
if(arr[left] + arr[right] == target){
temp[0] = arr[left];
temp[1] = arr[right];
res.push_back(temp);
while(left < right && arr[left] == arr[left + 1])left++;
while(left < right && arr[right] == arr[right - 1])right--;
left++;
right--;
}
else if(arr[left] + arr[right] > target)right--;
else left ++;
}
}
else{
for(int i = start; i < (int)arr.size() - k + 1; i++){
if(i > start && arr[i] == arr[i - 1])continue;
vector < vector <int> > temp = kSum(arr, i + 1, k - 1, target - arr[i]);
for(int j = 0; j < temp.size(); j++){
temp[j].push_back(arr[i]);
}
addAll(res, temp);
}
}
return res;
}
};



void print_vector(vector<vector<int> > v){
cout << "[";
for(int i = 0; i<v.size(); i++){
cout << "[";
for(int j = 0; j <v[i].size(); j++){
cout << v[i][j] << ", ";
}
cout << "],";
}
cout << "]"<<endl;
}




void main(){
Solution ob;
vector<int> v = {1,0,-1,0,-2,2};
print_vector(ob.fourSum(v, 0));
}
92 changes: 92 additions & 0 deletions 4_Sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

/*this code is edited by batrakeshav10
sir please accept my pull request and guide me,
so that i can win hactoberfest tshirt */
// Question-

/* Suppose we have an array of numbers. It stores n integers, there are four elements a, b, c and d in the array. We have another target value, such that a + b + c + d = target. Find all the unique quadruplets in the array which satisfies the situation. So if the array is like [-1,0,1,2,0,-2] and target is 0, then the result will be [[-1, 0, 0, 1],[-2, -1, 1, 2], [-2, 0, 0, 2]]
Input-
[1,0,-1,0,-2,2]
0
Output
[[1,2,-1,-2],[0,2,0,-2],[0,1,0,-1]] */



#include <bits/stdc++.h>
using namespace std;


class Solution {
public:
void addAll(vector < vector <int> >& res, vector < vector <int> >& temp){
for(int i = 0; i < temp.size(); i++)res.push_back(temp[i]);
}
vector<vector<int>> fourSum(vector<int>& nums, int target) {
sort(nums.begin(), nums.end());
return kSum(nums, 0, 4, target);
}
vector < vector <int> > kSum(vector <int>& arr, int start, int k, int target){
vector < vector <int> > res;
if(k == 2){
int left = start;
int right = arr.size() - 1;
vector <int> temp(2);
while(left < right){
if(arr[left] + arr[right] == target){
temp[0] = arr[left];
temp[1] = arr[right];
res.push_back(temp);
while(left < right && arr[left] == arr[left + 1])left++;
while(left < right && arr[right] == arr[right - 1])right--;
left++;
right--;
}

/*this code is edited by batrakeshav10
sir please accept my pull request and guide me,
so that i can win hactoberfest tshirt */
else if(arr[left] + arr[right] > target)right--;
else left ++;
}
}
else{
for(int i = start; i < (int)arr.size() - k + 1; i++){
if(i > start && arr[i] == arr[i - 1])continue;
vector < vector <int> > temp = kSum(arr, i + 1, k - 1, target - arr[i]);
for(int j = 0; j < temp.size(); j++){
temp[j].push_back(arr[i]);
}
addAll(res, temp);
}
}
return res;
}
};



void print_vector(vector<vector<int> > v){
cout << "[";
for(int i = 0; i<v.size(); i++){
cout << "[";
for(int j = 0; j <v[i].size(); j++){
cout << v[i][j] << ", ";
}
cout << "],";
}
cout << "]"<<endl;
}




void main(){
Solution ob;
vector<int> v = {1,0,-1,0,-2,2};
print_vector(ob.fourSum(v, 0));
}

/*this code is edited by batrakeshav10
sir please accept my pull request and guide me,
so that i can win hactoberfest tshirt */
22 changes: 22 additions & 0 deletions Armstrongnumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//finding armstrong number in java
public class Armstrong {

public static void main(String[] args) {

int number = 371, originalNumber, remainder, result = 0;

originalNumber = number;

while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, 3);
originalNumber /= 10;
}

if(result == number)
System.out.println(number + " is an Armstrong number.");
else
System.out.println(number + " is not an Armstrong number.");
}
}
26 changes: 26 additions & 0 deletions C#/RadianDegreeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace Conversions
{
public static class RadianDegreeConverter
{
/// <summary>
/// Converts given degree to radian
/// </summary>
/// <param name="degree"></param>
/// <returns></returns>
public static double DegreeToRadian(double degree)
{
return degree * (Math.PI / 180);
}

/// <summary>
/// Converts given radian to degree
/// </summary>
/// <returns></returns>
public static double RadianToDegree(double radian)
{
return radian * (180 / Math.PI);
}
}
}
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this repository is only for algorithms in which you can upload any language's algorithms which will useful for many other people.
happy coading 👨‍💻.
143 changes: 143 additions & 0 deletions CPP/4sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// C++ program to find four
// elements with the given sum
#include <bits/stdc++.h>

using namespace std;

// Function to find 4 elements that add up to
// given sum

void fourSum(int X, int arr[], map<int,

pair<int, int>> Map, int N)
{

int temp[N];


// Iterate from 0 to temp.length

for (int i = 0; i < N; i++)

temp[i] = 0;


// Iterate from 0 to arr.length

for (int i = 0; i < N - 1; i++)

{


// Iterate from i + 1 to arr.length

for (int j = i + 1; j < N; j++)

{


// Store curr_sum = arr[i] + arr[j]

int curr_sum = arr[i] + arr[j];


// Check if X - curr_sum if present

// in map

if (Map.find(X - curr_sum) != Map.end())

{


// Store pair having map value

// X - curr_sum

pair<int, int> p = Map[X - curr_sum];


if (p.first != i && p.second != i

&& p.first != j && p.second != j

&& temp[p.first] == 0

&& temp[p.second] == 0 && temp[i] == 0

&& temp[j] == 0)

{


// Print the output

cout << arr[i] << "," << arr[j] <<

"," << arr[p.first] << "," << arr[p.second];

temp[p.second] = 1;

temp[i] = 1;

temp[j] = 1;

break;

}

}

}

}
}

// Program for two Sum

map<int, pair<int, int>> twoSum(int nums[], int N)
{

map<int, pair<int, int>> Map;

for (int i = 0; i < N - 1; i++)

{

for (int j = i + 1; j < N; j++)

{

Map[nums[i] + nums[j]].first = i;

Map[nums[i] + nums[j]].second = j;

}

}

return Map;
}

// Driver code

int main()
{

int arr[] = { 10, 20, 30, 40, 1, 2 };

int n = sizeof(arr) / sizeof(arr[0]);

int X = 91;

map<int, pair<int, int>> Map = twoSum(arr, n);



// Function call

fourSum(X, arr, Map, n);


return 0;
}
Loading