Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ujjwamishraCSE27/RemoveDuplicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.Scanner;

public class RemoveDuplicates {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of elements: ");
int n = sc.nextInt();
int[] nums = new int[n];

System.out.print("Enter the sorted elements: ");
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}


if (n == 0) {
System.out.println("Unique count: 0");
return;
}

int k = 1;

for (int i = 1; i < n; i++) {
if (nums[i] != nums[k - 1]) {
nums[k] = nums[i];
k++;
}
}


System.out.println("Unique count: " + k);
System.out.print("Modified array: ");
for (int i = 0; i < k; i++) {
System.out.print(nums[i] + " ");
}
System.out.println();
}
}
42 changes: 42 additions & 0 deletions ujjwamishraCSE27/TwoSum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.Scanner;

public class TwoSum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);


System.out.print("Enter the number of elements: ");
int n = sc.nextInt();
int[] nums = new int[n];


System.out.print("Enter the elements: ");
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}


System.out.print("Enter the target sum: ");
int target = sc.nextInt();


int i, j;
boolean found = false;

for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (nums[i] + nums[j] == target) {
System.out.println("Output: [" + i + ", " + j + "]");
found = true;
break;
}
}
if (found) break;
}

if (!found) {
System.out.println("No two elements found that sum up to target.");
}
}
}