Skip to content

Commit e0301e0

Browse files
committed
Array Programs
1 parent 7e1ee19 commit e0301e0

20 files changed

+41
-45
lines changed

InterviewPrograms/src/com/java/array/ArrayRotation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* Rotate the Given array d times
7-
*
7+
* -------------------------------
88
* Write java program to rotate (clockwise) the given array
99
* d number of times.
1010
*

InterviewPrograms/src/com/java/array/Average.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.java.array;
22

33
/*
4-
* Calculate the Average of Given Array
5-
*
4+
* Calculate the Average of Given Array
5+
* -------------------------------------
6+
*
67
* This is one basic program using array.
78
* Steps
89
* 1. Declare a variable sum with 0

InterviewPrograms/src/com/java/array/FindAllDuplicates.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* Find All duplicate elements
7-
*
7+
* ---------------------------
88
* Write java program to find all the duplicates
99
* elements from the given array.
1010
*

InterviewPrograms/src/com/java/array/FindMissingNo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.java.array;
22
/*
3-
* Find the Missing Number in 1 to N
4-
*
3+
* Find the Missing Number in 1 to N
4+
* ----------------------------------
55
* An array contains 1 to N numbers
66
* but one number in the array is missing
77
* Write the java program to find the missing no
@@ -25,6 +25,7 @@
2525
* missing no = 45 - 37
2626
*
2727
* Note::
28+
* ------
2829
* This approach will work only for array contains
2930
* value from 1 to n (order does not matter)
3031
*/
@@ -40,7 +41,7 @@ public static void main(String[] args) {
4041
arraySum += v;
4142

4243
//array length is 8
43-
//one no is missing, then n should by n+1
44+
//one no is missing, then n should be n+1
4445
// here 8+1
4546
n = n+1;
4647

InterviewPrograms/src/com/java/array/FindMostFrequent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/*
44
* Find the Most Frequent Element in an Array
5+
* -------------------------------------------
56
* Using Brute Force Approach
67
*
78
* For the each element, scan the entire array

InterviewPrograms/src/com/java/array/FindMostFrequentUsingHashtable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* Find the Most Frequent Element in an Array
7-
*
7+
* ------------------------------------------
88
* Using Hash Table
99
*
1010
* We can create a hash table and store elements and

InterviewPrograms/src/com/java/array/FindMostFrequentUsingSorting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/*
66
* Find the Most Frequent Element in an Array
7-
*
7+
* ------------------------------------------
88
* Using Sorting
99
*
1010
* Lets sort the given array.

InterviewPrograms/src/com/java/array/FindPairForZ.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
/*
66
* Find the Pair (X,Y) whose sum is Z
7+
* -----------------------------------
78
*
89
* say the given array is {2,45,7,3,5,1,8,9}
910
* and Z = 10
1011
* Find the pairs (x,y) whose sum is 10
1112
* (2,8), (1,9), (3,7) are the pairs
1213
*
1314
* Solution
15+
* ---------
1416
* 1. Sort the given array (ascending order)
1517
* 2. Declare left pointer (l) which points to
1618
* left most element of the array (min of array)

InterviewPrograms/src/com/java/array/FindUniqueElt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/*
44
* Find the only one unique Element in the Array
5+
* ---------------------------------------------
56
*
67
* In the given array only one element is
78
* occurred one time, all the other elements are
@@ -16,7 +17,7 @@
1617
* Write the program to calculate 6
1718
*
1819
* Solution
19-
*
20+
* --------
2021
* use ^ (XOR) operator
2122
* apply ^ (XOR) operator to all the values
2223
* in the array.

InterviewPrograms/src/com/java/array/FindingAllSubsets.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.java.array;
22

33
/*
4-
* Find All Possible Subsets of Given Array
4+
* Find All Possible Subsets of Given Array
5+
* ----------------------------------------
6+
* say Given array is
7+
* {a, b, c, d}
58
*
6-
* say Given array is
7-
* {a, b, c, d}
8-
*
9-
* Possible subsets are
10-
* {a} {b} {c} {d}
11-
* {a, b} {a, c} {a, d} {b, c} {b, d} {c, d}
12-
* {a, b, c} {a, b, d} {a, c, d} {b, c, d}
13-
* {a, b, c, d}
9+
* Possible subsets are
10+
* {a} {b} {c} {d}
11+
* {a, b} {a, c} {a, d} {b, c} {b, d} {c, d}
12+
* {a, b, c} {a, b, d} {a, c, d} {b, c, d}
13+
* {a, b, c, d}
1414
*
1515
*/
1616
public class FindingAllSubsets {

0 commit comments

Comments
 (0)