Skip to content

Commit

Permalink
Another wave is done
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonePY committed Apr 12, 2023
1 parent 90b7161 commit dfff962
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions SeventhWave/1darray2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int m = scanner.nextInt();
int[] arr = new int[n];
for (int j = 0; j < n; j++) {
arr[j] = scanner.nextInt();
}
solve(n, m, arr);
}
}

public static void solve(int n, int m, int[] arr) {
if (solve(n, m, arr, new boolean[n], 0)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}

public static boolean solve(int n, int m, int[] arr, boolean[] visited, int curr) {
if (curr + m >= n || curr + 1 == n) {
return true;
}

boolean[] newVisited = new boolean[n];
for (int i = 0; i < n; i++) {
newVisited[i] = visited[i];
}

boolean s = false;
if (!visited[curr + 1] && arr[curr + 1] == 0) {
newVisited[curr + 1] = true;
s = solve(n, m, arr, newVisited, curr + 1);
}
if (s) {
return true;
}
if (m > 1 && arr[curr + m] == 0 && !visited[curr + m]) {
newVisited[curr + m] = true;
s = solve(n, m, arr, newVisited, curr + m);
}
if (s) {
return true;
}
if (curr > 0 && arr[curr - 1] == 0 && !visited[curr - 1]) {
newVisited[curr - 1] = true;
s = solve(n, m, arr, newVisited, curr - 1);
}
return s;
}
}
40 changes: 40 additions & 0 deletions SeventhWave/arraylist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);

int total = scan.nextInt();

ArrayList<ArrayList<Integer>> mainlist = new ArrayList<>();

for (int i = 0; i < total; i++) {
int size = scan.nextInt();
ArrayList<Integer> list = new ArrayList();

for (int j = 0; j < size; j++) {
int item = scan.nextInt();
list.add(item);
}
mainlist.add(list);
}

int totalprint = scan.nextInt();
for (int k = 0; k < totalprint; k++) {
int row = scan.nextInt();
int col = scan.nextInt();
try {
System.out.println(mainlist.get(row - 1).get(col - 1));
} catch (Exception e) {
System.out.println("ERROR!");
}
}
scan.close();
}
}
36 changes: 36 additions & 0 deletions SeventhWave/dstructures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
try {
int no_of_entries = 0;
int i = 0;
String name = null;
int number = 0;
String query = null;
HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
BufferedReader b = new BufferedReader(new InputStreamReader(
System.in));
no_of_entries = Integer.parseInt(b.readLine());
while (i < no_of_entries) {
name = b.readLine();
number = Integer.parseInt(b.readLine());
phoneBook.put(name, number);
i++;
}
while (!(query = b.readLine().trim()).isEmpty()) {
if (phoneBook.containsKey(query))
System.out.println(query + "=" + phoneBook.get(query));
else
System.out.println("Not found");
}
} catch (Exception e) {

}
}
}
38 changes: 38 additions & 0 deletions SeventhWave/list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
final int size = in.nextInt();
final List<Integer> list = new LinkedList<>();
for (int i = 0; i < size; i++) {
list.add(in.nextInt());
}
final int commandCount = in.nextInt();
for (int i = 0; i < commandCount; i++) {
in.nextLine();
String command = in.nextLine();
if (command.equals("Insert")) {
int index = in.nextInt();
int value = in.nextInt();
list.add(index, value);
} else {
int index = in.nextInt();
list.remove(index);
}
}
int count = 0;
for (Integer number : list) {
System.out.print(number);
if (count != list.size() - 1) {
System.out.print(" ");
}
count++;
}
}
}
39 changes: 39 additions & 0 deletions SeventhWave/stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static boolean isBalanced(String s) {
Stack<Character> stack = new Stack<Character>();
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == '(') stack.push('(');
else if (s.charAt(i) == '{') stack.push('{');
else if (s.charAt(i) == '[') stack.push('[');
else if (s.charAt(i) == ')') {
if (stack.isEmpty()) return false;
if (stack.pop() != '(') return false;
} else if (s.charAt(i) == '}') {
if (stack.isEmpty()) return false;
if (stack.pop() != '{') return false;
} else if (s.charAt(i) == ']') {
if (stack.isEmpty()) return false;
if (stack.pop() != '[') return false;
}
}
return stack.isEmpty();
}

public static void main(String[] args) {
Stack<Character> stack = new Stack<Character>();
Scanner sc = new Scanner(System.in);
String line;
while (sc.hasNextLine()) {
line = sc.nextLine();
if (isBalanced(line)) System.out.println("true");
else System.out.println("false");
}
}
}

0 comments on commit dfff962

Please sign in to comment.