Tasks Details
easy
1.
EquiLeader
Find the index S such that the leaders of the sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N - 1] are the same.
Task Score
100%
Correctness
100%
Performance
100%
A non-empty array A consisting of N integers is given.
The leader of this array is the value that occurs in more than half of the elements of A.
An equi leader is an index S such that 0 ≤ S < N − 1 and two sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N − 1] have leaders of the same value.
For example, given array A such that:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2we can find two equi leaders:
- 0, because sequences: (4) and (3, 4, 4, 4, 2) have the same leader, whose value is 4.
- 2, because sequences: (4, 3, 4) and (4, 4, 2) have the same leader, whose value is 4.
The goal is to count the number of equi leaders.
Write a function:
class Solution { public int solution(int[] A); }
that, given a non-empty array A consisting of N integers, returns the number of equi leaders.
For example, given:
A[0] = 4 A[1] = 3 A[2] = 4 A[3] = 4 A[4] = 4 A[5] = 2the function should return 2, as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000,000..1,000,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used Java 8
Time spent on task 25 minutes
Notes
not defined yet
Task timeline
Code: 12:58:30 UTC,
java,
autosave
Code: 12:58:37 UTC,
java,
autosave
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
int pos = -1;
if(item.isEmpty()){
return -1;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return -1;
}
// write your code in Java SE 8
}
}
Code: 12:58:49 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
int pos = -1;
if(item.isEmpty()){
return -1;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return -1;
}
// write your code in Java SE 8
}
}
Code: 12:58:59 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
int pos = -1;
if(item.isEmpty()){
return -1;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return -1;
}
}
}
Code: 13:01:03 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
int pos = -1;
if(item.isEmpty()){
return -1;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return 0;
}
}
}
Code: 13:01:20 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
int pos = -1;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return 0;
}
}
}
Code: 13:01:30 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
for(int i=0; i<A.length; i++){
if(A[i] == num){
if(pos == -1){
pos = i;
}
cnt++;
}
}
if(A.length / 2 < cnt) {
return pos;
}else{
return 0;
}
}
}
Code: 13:01:51 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
}
}
Code: 13:02:13 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int
}
}
Code: 13:02:28 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
}
}
Code: 13:02:56 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
for(int i=0; i<A.length; i++){
}
}
}
Code: 13:03:20 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
int cnt=0;
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int cnt = 0;
for(int i=0; i<A.length; i++){
B[i]
}
}
}
Code: 13:03:39 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int cnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
}
}
}
}
Code: 13:04:01 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
}
}
}
}
Code: 13:04:12 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
}
}
}
Code: 13:04:35 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
}
}
Code: 13:04:51 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
}
}
Code: 13:05:02 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=0; i<A.length; i++){
if()
}
}
}
Code: 13:05:16 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A)
}
}
}
Code: 13:05:39 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[)
}
}
}
Code: 13:05:59 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > i / 2)
}
}
}
Code: 13:06:36 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > ㅡㅁi / 2)
}
}
}
Code: 13:06:47 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil(i / 2))
}
}
}
Code: 13:06:58 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) )
}
}
}
Code: 13:07:20 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > )
}
}
}
Code: 13:07:30 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)i / 2f))
}
}
}
Code: 13:07:41 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length i) / 2f))
}
}
}
Code: 13:08:00 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
Compile error
Solution.java:19: error: incompatible types: int[] cannot be converted to int int B = new int[A.length]; ^ Solution.java:25: error: array required, but int found B[i] = ncnt; ^ 2 errors
Code: 13:08:14 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:08:14 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 0 expected 2
Code: 13:08:44 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println()
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:08:49 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(A[i-1]);
if(A[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
4 3 4 4 4
Code: 13:09:15 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(A[i-1]);
if(B[i-1] > Math.ceil((float)i / 2f) && A[A.length -1] - A[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:09:18 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1]);
if(B[i-1] > Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
1 1 2 3 4
Code: 13:09:53 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > Math.ceil((float)i / 2f));
if(B[i-1] > Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:09:54 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > Math.ceil((float)i / 2f));
if(B[i-1] > Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] > Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
false false false true true
Code: 13:10:07 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > Math.ceil((float)i / 2f));
if(B[i-1] >= Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 4 expected 2
stdout:
false false false true true
Code: 13:10:22 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(Math.ceil((float)i / 2f));
if(B[i-1] >= Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 4 expected 2
stdout:
1.0 1.0 2.0 2.0 3.0
Code: 13:10:47 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(Math.ceil((float)i / 2f));
if(B[i-1] >= (Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:10:49 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(Math.ceil((float)i / 2f));
if(B[i-1] >= (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 4 expected 2
stdout:
1.0 1.0 2.0 2.0 3.0
Code: 13:10:56 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(Math.ceil((float)i / 2f));
if(B[i-1] >= (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 4 expected 2
stdout:
1.0 1.0 2.0 2.0 3.0
Code: 13:11:12 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if(B[i-1] >= (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 4 expected 2
stdout:
1 1 2 2 3
Code: 13:11:27 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= (int)Math.ceil((float)i / 2f));
if(B[i-1] >= (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:11:27 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= (int)Math.ceil((float)i / 2f));
if(B[i-1] >= (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 4 expected 2
stdout:
true true true true true
Code: 13:13:56 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= (int)Math.ceil((float)i / 2f));
if(B[i-1] > (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] >= (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:13:58 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= (int)Math.ceil((float)i / 2f));
if(B[i-1] > (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
true true true true true
Code: 13:14:17 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > (int)Math.ceil((float)i / 2f));
if(B[i-1] > (int)Math.ceil((float)i / 2f) && B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
false false false true true
Code: 13:16:36 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > (int)Math.ceil((float)i / 2f));
if(B[i-1] > (int)Math.ceil((float)i / 2f)
&& B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:16:40 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if(B[i-1] > (int)Math.ceil((float)i / 2f)
&& B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
1 1 2 2 3
Code: 13:17:10 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if(iB[i-1] > (int)Math.ceil((float)i / 2f)
&& B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:17:20 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if(i==1B[i-1] > (int)Math.ceil((float)i / 2f)
&& B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:17:45 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:17:55 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& ( B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f)){
ans++;
}
}
return ans;
}
}
Code: 13:18:21 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 0 expected 2
stdout:
1 1 2 2 3
Code: 13:18:36 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f)));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:18:36 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f)));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
true false false true true
Code: 13:19:07 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((B[i-1] > (int)Math.ceil((float)i / 2f)));
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:19:10 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println((B[i-1]);
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
Compile error
Solution.java:30: error: ')' expected System.out.println((B[i-1]); ^ 1 error
Code: 13:19:15 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1]);
if((i==1 ? B[i-1] >0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
1 1 2 3 4
Code: 13:19:39 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1]);
if((i==1 ? B[i-1] > 0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:19:48 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > (int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] > 0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
false false false true true
Code: 13:20:04 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > (int)Math.ceil((float)i / 2f));
System.out.println(B[i-1] > (int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] > 0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:20:08 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1]);
System.out.println((int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] > 0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 0 expected 2
stdout:
1 1 1 1 2 2 3 2 4 3
Code: 13:20:23 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println("B : " + B[i-1]);
System.out.println((int)Math.ceil((float)i / 2f));
if((i==1 ? B[i-1] > 0 : B[i-1] > (int)Math.ceil((float)i / 2f))
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
B : 1 1 B : 1 1 B : 2 2 B : 3 2 B : 4 3
Code: 13:21:35 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println("B : " + B[i-1]);
System.out.println((int)Math.ceil((float)i / 2f));
if(B[]
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:21:48 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println("B : " + B[i-1]);
System.out.println((int)Math.ceil((float)i / 2f));
if(B[i-1] > i/2 + 1
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:21:51 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] > i/2 + 1);
if(B[i-1] > i/2 + 1
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
WRONG ANSWER,
got 0 expected 2
stdout:
false false false false true
Code: 13:22:07 UTC,
java,
verify,
result: Failed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= i/2 + 1);
if(B[i-1] >= i/2 + 1
&& (A.length - i == 1 ? B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.008 s
WRONG ANSWER,
got 0 expected 2
stdout:
true false true true true
Code: 13:22:20 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= i/2 + 1);
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] > 0 : B[A.length -1] - B[i-1] > (int)Math.ceil((float)(A.length - i) / 2f))){
ans++;
}
}
return ans;
}
}
Code: 13:22:30 UTC,
java,
autosave
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= i/2 + 1);
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] > ){
ans++;
}
}
return ans;
}
}
Code: 13:22:43 UTC,
java,
verify,
result: Passed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
System.out.println(B[i-1] >= i/2 + 1);
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] >= (A.length - i)/2 + 1){
ans++;
}
}
return ans;
}
}
Analysis
expand all
Example tests
1.
0.004 s
OK
stdout:
true false true true true
Code: 13:22:53 UTC,
java,
verify,
result: Passed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] >= (A.length - i)/2 + 1){
ans++;
}
}
return ans;
}
}
Analysis
Code: 13:23:00 UTC,
java,
verify,
result: Passed
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] >= (A.length - i)/2 + 1){
ans++;
}
}
return ans;
}
}
Analysis
Code: 13:23:04 UTC,
java,
final,
score: 
100
import java.util.*;
class Solution {
public int solution(int[] A) {
Stack<Integer> item = new Stack<>();
for(int i=0; i<A.length; i++){
if(item.isEmpty() || item.peek() == A[i]){
item.push(A[i]);
}else{
item.pop();
}
}
if(item.isEmpty()){
return 0;
}
int num = item.pop();
int[] B = new int[A.length];
int ncnt = 0;
for(int i=0; i<A.length; i++){
if(A[i] == num){
ncnt+=1;
}
B[i] = ncnt;
}
int ans = 0;
for(int i=1; i<A.length; i++){
if(B[i-1] >= i/2 + 1
&& B[A.length -1] - B[i-1] >= (A.length - i)/2 + 1){
ans++;
}
}
return ans;
}
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N)
expand all
Correctness tests
1.
0.004 s
OK
2.
0.004 s
OK
3.
0.008 s
OK
1.
0.008 s
OK
2.
0.004 s
OK
3.
0.004 s
OK
1.
0.004 s
OK
2.
0.004 s
OK
1.
0.008 s
OK
1.
0.004 s
OK