Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
sabira-khan committed May 6, 2022
1 parent 4050014 commit f2925c8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions JavaSolutions/src/com/gitproject/Beecrowd1062_uri.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.gitproject;

import java.util.Scanner;
import java.util.Stack;

public class Beecrowd1062_uri {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean t = true;

while (s.nextInt() != 0) {
int n = s.nextInt();

System.out.print( t ? "" : "\n");

while (s.nextInt() != 0) {
Stack<Integer> stack = new Stack<>();
s.nextLine();
String line = s.nextLine();
String[] train = line.split(" ");
int current = 0;
int coach = Integer.parseInt(train[current]);
for (int i = 1; i <= n; i++) {
stack.push(i);
while (!stack.isEmpty() && coach == stack.lastElement()) {
if (++current < n) {
coach = Integer.parseInt(train[current]);
}
stack.pop();
}
}
System.out.println(stack.isEmpty() ? "Yes" : "No");
}
t = false;
}
System.out.println();
}
}

0 comments on commit f2925c8

Please sign in to comment.