Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding new solutions of Leetcode
  • Loading branch information
rath23 committed Jul 12, 2023
commit 015f9775651ed3f429ff18345e9032b722662a25
45 changes: 45 additions & 0 deletions ArraysSolutions/Find All Duplicates in an Array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Solution of Find All Duplicates in an Array

#### Time Complexity - O (n)

#### Space Complexity - O(1)

```java

class Solution {

public List<Integer> findDuplicates(int[] nums) {

List <Integer> list = new ArrayList <Integer>();

int start=0;

int ref;

Arrays.sort(nums);

for (int i = 0 ; i < nums.length-1 ; i++){

ref = nums[i] ^ nums[i+1];

if(ref == 0 ){

list.add(start,nums[i]);

start++;

}

}

return list;

}

}

```

<div align="right">
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
</div>
57 changes: 57 additions & 0 deletions ArraysSolutions/Removing-minimum-and-maximum-from-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Solution of Removing-minimum-and-maximum-from-array
#### Time Complexity - O (n)
#### Space Complexity - O(1)

```java
class Solution {
public int minimumDeletions(int[] nums) {
int arrayLength = nums.length;
int max=nums[0];
int maxIndex = 0;
int min=nums[0];
int minIndex = 0;

for (int i = 0 ; i < nums.length; i++){
if (max<nums[i]){
max = nums[i] ;
maxIndex = i;
}
if (min>nums[i]){
min = nums[i] ;
minIndex=i;
}
}
int c1,c2,c3;
if(minIndex > maxIndex){
c1 = (maxIndex +1) + (arrayLength - minIndex);
c2 = minIndex + 1;
c3 = arrayLength - maxIndex;
}

else if(maxIndex > minIndex){
c1 = (minIndex +1) + (arrayLength - maxIndex);
c2 = maxIndex + 1;
c3 = arrayLength - minIndex;
}
else {
c1=c2=c3=maxIndex+1;
}

if ( c1 < c2 && c1 < c3 ){
return c1;
}
else if (c2 < c1 && c2 < c3){
return c2;
}
else if (c3 < c1 && c3 < c2){
return c3;
}
else {
return c2;
}
}
}
```
<div align="right">
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
</div>
22 changes: 22 additions & 0 deletions ArraysSolutions/Reverse an Array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Solution of Reverse an Array
#### Time Complexity - O (n)
#### Space Complexity - O(1)

```java
class Solution {
public void reverseString(char[] s) {
int start = 0;
int end = s.length-1;
while ( start < end){
char temp = s[start];
s[start] = s[end];
s[end]= temp;
start++;
end--;
}
}
}
```
<div align="right">
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
</div>
28 changes: 28 additions & 0 deletions ArraysSolutions/Rotate-Array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Solution of Rotate-Array
#### Time Complexity - O (n)
#### Space Complexity - O(1)

```java
class Solution {
public static void reverse(int [] a , int start , int end ){
while (start <end){
int temp = a[start];
a[start]=a[end];
a[end] = temp;
start++;
end--;
}
}

public void rotate(int[] nums, int k) {
int n = nums.length;
k = k%n;
reverse(nums,(n-k),(n-1));
reverse(nums,0,(n-k-1));
reverse(nums,0,(n-1));
}
}
```
<div align="right">
Contributed By <a href="https://github.com/rath23"> Muneer Ahmad</a>
</div>