Skip to content

Commit 5fda052

Browse files
committed
solve repeatingElementsInArray
1 parent 4ee225b commit 5fda052

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
/*******************************************************************************************************
3+
/* ___ _ _ _ _
4+
/* / _ \ | | (_)| | | |
5+
/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___
6+
/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __|
7+
/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \
8+
/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/
9+
/* __/ |
10+
/* |___/
11+
/******************************************************************************************************/
12+
13+
/***********************************
14+
/* Find two repeating elements in an Array
15+
/***********************************/
16+
17+
// Library imports
18+
#include <iostream>
19+
using namespace std;
20+
21+
//Prototypes for the algorithms
22+
void repeatingElementsInArray(int* arr,int arrLen);
23+
24+
int main(){
25+
// Lines to handle user input go here, be descriptive...
26+
// use cin, cout
27+
int testArray[] ={4, 2, 4, 5, 2, 3, 1};
28+
29+
int arrayLength = sizeof(testArray)/sizeof(testArray[0]);
30+
31+
// Call your algorithms here
32+
repeatingElementsInArray(testArray,arrayLength);
33+
34+
return 0;
35+
}
36+
37+
/**********************************************************
38+
/* <repeatingElementsInArray>
39+
/*
40+
/* @description : description here
41+
/* @param : Integer<variable> (Datatype<variable_name>)
42+
/* @return : datatype (int,float,double etc)
43+
/* @complexity : Big O notation. (O(n),O(n^2) etc)
44+
/* @explanation : Detailed description about what the algorithm does
45+
/* @author : <Your name> @<GitHub handle> (John Doe @johndoe)
46+
/**********************************************************/
47+
void repeatingElementsInArray(int* arr,int arrLen){
48+
// Algorithm content goes here.
49+
for(int i=0;i<arrLen;i++){
50+
for(int j=i+1;j<arrLen;j++){
51+
if(arr[i]==arr[j]){
52+
cout<<arr[i]<<" ";
53+
}
54+
}
55+
}
56+
cout<<endl;
57+
}

Arrays and Strings/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@
7070
Intersection= {3,5}
7171

7272

73+
#### 12. [Find two repeating elements in an Array (repeatingElementsInArray))](C++/repeatingElementsInArray.cpp)
74+
75+
Find the two repeating elements in a given array
76+
You are given an array of n+2 elements. All elements of the array are in range 1 to n. And all elements occur once except two numbers which occur twice. Find the two repeating numbers.
77+
A= {4, 2, 4, 5, 2, 3, 1} and n = 5
78+
79+
The above array has n + 2 = 7 elements with all elements occurring once except 2 and 4 which occur twice. So the output should be 4 2.
80+
81+
82+
83+
84+
7385
TODO :
7486

7587

@@ -81,12 +93,8 @@ Input = {12, 34, 45, 9, 8, 90, 3}
8193
Output = {12, 34, 8, 90, 45, 9, 3}
8294

8395

84-
* Find the two repeating elements in a given array
85-
You are given an array of n+2 elements. All elements of the array are in range 1 to n. And all elements occur once except two numbers which occur twice. Find the two repeating numbers.
8696

87-
For example, array = {4, 2, 4, 5, 2, 3, 1} and n = 5
8897

89-
The above array has n + 2 = 7 elements with all elements occurring once except 2 and 4 which occur twice. So the output should be 4 2.
9098

9199
* Equilibrium index of an array
92100
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For example, in an arrya A:

0 commit comments

Comments
 (0)