codingChallenge
This commit is contained in:
parent
52f6f2a1a8
commit
afc94ab8a8
@ -1,11 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="Unnamed" type="Application" factoryName="Application" nameIsGenerated="true">
|
|
||||||
<option name="ALTERNATIVE_JRE_PATH" value="17" />
|
|
||||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
|
|
||||||
<option name="MAIN_CLASS_NAME" value="Amazon" />
|
|
||||||
<module name="MvnDemo" />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
BIN
Alone.class
Normal file
BIN
Alone.class
Normal file
Binary file not shown.
23
Alone.java
Normal file
23
Alone.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
public class Alone {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int[] ar = { 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9 };
|
||||||
|
lonelyNum(ar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void lonelyNum(int[] arr) {
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (int k = 0; k < arr.length; k++) {
|
||||||
|
if (arr[i] == arr[k]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 1) {
|
||||||
|
System.out.println(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
JavaList.class
Normal file
BIN
JavaList.class
Normal file
Binary file not shown.
29
JavaList.java
Normal file
29
JavaList.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class JavaList {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
/*
|
||||||
|
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your
|
||||||
|
* class should be named Solution.
|
||||||
|
*/
|
||||||
|
List<Integer> L = new ArrayList<>();
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.print("Enter the number of Queries: ");
|
||||||
|
int Q = scan.nextInt();
|
||||||
|
while (Q-- > 0) {
|
||||||
|
int N = scan.nextInt();
|
||||||
|
L.add(N);
|
||||||
|
}
|
||||||
|
int x = scan.nextInt();
|
||||||
|
int y = scan.nextInt();
|
||||||
|
L.add(x, y);
|
||||||
|
int xagain = scan.nextInt();
|
||||||
|
L.remove(xagain);
|
||||||
|
for (int i = 0; i < L.size(); i++) {
|
||||||
|
System.out.print(L.get(i) + " ");
|
||||||
|
}
|
||||||
|
scan.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/main/java/Alone.java
Normal file
24
src/main/java/Alone.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Alone
|
||||||
|
*/
|
||||||
|
public class Alone {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] arr = { 1, 1, 1, 3, 4, 4, 5, 5, 5, 5 };
|
||||||
|
System.out.println(lonelyNum(arr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int lonelyNum(int[] nums) {
|
||||||
|
int count = 0;
|
||||||
|
nums[0] = 0;
|
||||||
|
for (int x : nums) {
|
||||||
|
for (int i = 0; i < nums.length; i++) {
|
||||||
|
if (x != nums[i]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/java/PrepSession/Alonea.java
Normal file
23
src/main/java/PrepSession/Alonea.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* Alone
|
||||||
|
*/
|
||||||
|
public class Alonea {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] arr = { 1, 1, 1, 3, 4, 4, 5, 5, 5, 5 };
|
||||||
|
System.out.println(lonelyNum(arr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int lonelyNum(int[] nums) {
|
||||||
|
int count = 0;
|
||||||
|
int i = nums.length;
|
||||||
|
for (int x : nums) {
|
||||||
|
if (x == nums[i]) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
target/classes/Alone.class
Normal file
BIN
target/classes/Alone.class
Normal file
Binary file not shown.
BIN
target/classes/Alonea.class
Normal file
BIN
target/classes/Alonea.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user