Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit c08967c

Browse files
committed
Merge pull request #155 from saurabhjn76/master
Added some solutions in Java,python and c
2 parents 1bd4677 + e74f475 commit c08967c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

solutions/c/find-missing-element.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
// The differnce in sum of two arrays will give us the desired value.
4+
// The other approach could be to look up for element each time but that will increase the time complexity of the program.
5+
int find_missing(int orig[],int On,int shuffled[])
6+
{
7+
int i,sum=0;
8+
for(i=0;i<On-1;i++)
9+
sum+=orig[i]-shuffled[i];
10+
return sum+orig[On-1];
11+
}
12+
13+
int main()
14+
{
15+
int arr[]={1,3,5,6,2,5,6,8,9,23,45,67,87};
16+
int shuffled_arr[]={1,2,5,6,8,9,3,45,87,6,67,5};
17+
int On=sizeof(arr) / sizeof(arr[1]);
18+
printf("The missing value is:%d\n",find_missing(arr,On,shuffled_arr));
19+
return 0;
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
public class FindingMissingElement {
3+
4+
/**
5+
*The difference in the sum of the two arrays will give us the desired value
6+
*/
7+
static int find_missing(int a[],int b[])
8+
{
9+
int sum=0;
10+
for(int i:a)
11+
sum+=i;
12+
for(int i:b)
13+
sum-=i;
14+
return sum;
15+
}
16+
public static void main(String[] args) {
17+
int[] arr={1,3,5,6,2,5,6,8,9,23,45,67,87};
18+
int[] shuffled_ar={1,2,5,6,8,9,3,45,87,6,67,5};
19+
System.out.println("The missing value is:"+find_missing(arr,shuffled_ar));
20+
21+
22+
}
23+
24+
}

solutions/python/bubble-sort.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
def bubblesort(lst):
3+
for i in range(0,len(lst)-1):
4+
for j in range(i+1,len(lst)):
5+
if lst[i]>lst[j]:
6+
temp=lst[i]
7+
lst[i]=lst[j]
8+
lst[j]=temp
9+
return lst
10+
11+
l=[1,4,2,4,6,2,6,8,5,8,9,5]
12+
for i in bubblesort(l):
13+
print (i)

0 commit comments

Comments
 (0)