Skip to content

Commit 2ff45c6

Browse files
rath23rath23CodingWallah
authored
Update Subarray-sum-equals-k.md (CodingWallah#6)
* Update Subarray-sum-equals-k.md * Solution of missing number * Adding Solution of Rotate Array * Solution of Find All Duplicates in an Array * Solution of Reverse an Array * Updated hyper link of my profile * Removing profile and adding contrited by --------- Co-authored-by: rath23 <muneer@amityonline.com> Co-authored-by: Coding Wallah <121433611+CodingWallah@users.noreply.github.com>
1 parent d54f164 commit 2ff45c6

File tree

6 files changed

+123
-8
lines changed

6 files changed

+123
-8
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Solution of Find All Duplicates in an Array
2+
3+
#### Time Complexity - O (n)
4+
5+
#### Space Complexity - O(1)
6+
7+
```java
8+
9+
class Solution {
10+
11+
public List<Integer> findDuplicates(int[] nums) {
12+
13+
List <Integer> list = new ArrayList <Integer>();
14+
15+
int start=0;
16+
17+
int ref;
18+
19+
Arrays.sort(nums);
20+
21+
for (int i = 0 ; i < nums.length-1 ; i++){
22+
23+
ref = nums[i] ^ nums[i+1];
24+
25+
if(ref == 0 ){
26+
27+
list.add(start,nums[i]);
28+
29+
start++;
30+
31+
}
32+
33+
}
34+
35+
return list;
36+
37+
}
38+
39+
}
40+
41+
```
42+
43+
<div align="right">
44+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
45+
</div>

ArraysSolutions/Missing Number.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
## Solution of Missing-Number
3+
#### Time Complexity - O (n)
4+
#### Space Complexity - O(1)
5+
6+
```java
7+
class Solution {
8+
public int missingNumber(int[] nums) {
9+
int num = nums.length;
10+
int sunOfNaturalNumbers = num*(num+1)/2;
11+
int sumOfArrayNum = 0;
12+
for(int i = 0; i<num ; i++){
13+
sumOfArrayNum += nums[i];
14+
}
15+
return sunOfNaturalNumbers-sumOfArrayNum;
16+
}
17+
}
18+
```
19+
<div align="right">
20+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
21+
</div>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Solution of Reverse an Array
2+
#### Time Complexity - O (n)
3+
#### Space Complexity - O(1)
4+
5+
```java
6+
class Solution {
7+
public void reverseString(char[] s) {
8+
int start = 0;
9+
int end = s.length-1;
10+
while ( start < end){
11+
char temp = s[start];
12+
s[start] = s[end];
13+
s[end]= temp;
14+
start++;
15+
end--;
16+
}
17+
}
18+
}
19+
```
20+
<div align="right">
21+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
22+
</div>

ArraysSolutions/Rotate-Array.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Solution of Rotate-Array
2+
#### Time Complexity - O (n)
3+
#### Space Complexity - O(1)
4+
5+
```java
6+
class Solution {
7+
public static void reverse(int [] a , int start , int end ){
8+
while (start <end){
9+
int temp = a[start];
10+
a[start]=a[end];
11+
a[end] = temp;
12+
start++;
13+
end--;
14+
}
15+
}
16+
17+
public void rotate(int[] nums, int k) {
18+
int n = nums.length;
19+
k = k%n;
20+
reverse(nums,(n-k),(n-1));
21+
reverse(nums,0,(n-k-1));
22+
reverse(nums,0,(n-1));
23+
}
24+
}
25+
```
26+
<div align="right">
27+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
28+
</div>

ArraysSolutions/Subarray-sum-equals-k.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[ Profile ](https://github.com/rath23)
2-
========
3-
4-
### Solution Subarray sum equals to k
51
#### Time Complexity - O (n^2)
62
#### Space Complexity - O(1)
73

@@ -22,3 +18,6 @@ class Solution {
2218
}
2319
}
2420
```
21+
<div align="right">
22+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
23+
</div>

ArraysSolutions/Wave Array Solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
[ Profile ](https://github.com/rath23)
2-
========
3-
4-
### Solution of Wave Array
1+
## Solution of Wave Array
52
#### Time Complexity - O (n)
63
#### Space Complexity - O(1)
74

@@ -19,3 +16,6 @@ class Solution {
1916
}
2017
}
2118
```
19+
<div align="right">
20+
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
21+
</div>

0 commit comments

Comments
 (0)