WA Test Cases CodeChef Solution

Problem – WA Test Cases CodeChef Solution

Chef has recently introduced a feature, called WA Test Cases, which allows you to see the smallest test case that your WA code has failed in. For example, you can go to any relevant problem in Practice, make a submission which gets a WA verdict, and then click on the “Debug My Code” button to see the test case.

Your job now is to find that smallest test case that a particular submission fails on. That problem has NN test cases, and you are given the size of each of those test cases as S_1, S_2, \ldots, S_NS1​,S2​,…,SN​. You are also given a binary string VV, which tells whether the submission has passed a particular test case or not. That is, if the i^{th}ith bit of VV is 11, that means that the submission has passed the i^{th}ith test case. If it is 00, then it has failed that test case. Your job is the output the size of the smallest test case where the submission has failed.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains a single integer, NN.
    • The second line contains NN integers – S_1, S_2, \ldots, S_NS1​,S2​,…,SN
    • The third line contains a binary string – VV.

Output Format

For each test case, output on a new line, a single integer, which should be the size of the smallest test case where the submission has failed.

Constraints

  • 1 \leq T \leq 1001≤T≤100
  • 1 \leq N \leq 1001≤N≤100
  • 1 \leq S_i \leq 1001≤Si​≤100
  • Length of V = NV=N
  • Each element of VV is either 00 or 11
  • At least one element of VV will be 00

Sample 1:

Input: 5
3
5 10 3
000
3
5 10 3
001
3
5 5 3
001
3
5 5 3
101
5
10 100 100 10 10
00001

Output: 3
5
5
5
10

Explanation:

Test case 1: There are 33 test cases, and the submission has failed all the 33 test cases. The sizes of the test cases on which it has failed are \{5, 10, 3\}{5,10,3}. The smallest among these is 33, and so the answer is 33.

Test case 2: There are 33 test cases, and the submission has failed on 22 test cases. The sizes of the test cases on which it has failed are \{5, 10\}{5,10}. The smallest among these is 55, and so the answer is 55.

Test case 3: There are 33 test cases, and the submission has failed on 22 test cases. The sizes of the test cases on which it has failed are \{5, 5\}{5,5}. The smallest among these is 55, and so the answer is 55.

Test case 4: There are 33 test cases, and the submission has failed on 11 test case. The sizes of the test case on which it has failed is \{5\}{5}. The smallest among these is 55, and so the answer is 55.

Test case 5: There are 55 test cases, and the submission has failed on 44 test cases. The sizes of the test cases on which it has failed are \{10, 100, 100, 10\}{10,100,100,10}. The smallest among these is 1010, and so the answer is 1010.

WA Test Cases CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int t;
		Scanner sc=new Scanner(System.in);
		t=sc.nextInt();
		for(int i=0;i<t;i++){
		    int n=sc.nextInt();
		    int[] a=new int[n];
		    for(int j=0; j<n; j++){
		        a[j]=sc.nextInt();
		    }
		    int min=100;
		    String v=sc.next();
		    for(int j=0; j<n; j++){
		        if(v.charAt(j)=='0'){
		            int x=j;
		            min=Math.min(min,a[x]);
		        }
		    }
		    System.out.println(min);
		}   
	}
}

WA Test Cases CodeChef Solution in C++14

// #include <bits/stdc++.h>
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <queue>
#include <string>

#define ll long long int
#define arw ->
#define pb push_back
#define loop(i, a, n) for (ll i = a; i < n; i++)
#define vi vector<int>
using namespace std;

int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vi a;
        loop(i, 0, n)
        {
            int x;
            cin >> x;
            a.pb(x);
        }
        string s;
        cin >> s;
        int mn = INT_MAX;

        loop(i, 0, n)
        {
            if (s[i] == '0')
            {
                if (mn > a[i])
                {
                    mn = a[i];
                }
            }
        }

        cout << mn << endl;
    }
    return 0;
}

WA Test Cases CodeChef Solution in Python3

t=int(input())
for i in range(t):
    N=int(input())
    s=list(map(int,input().split()))
    v=input()
    b=[]
    for j in range(N):
        if v[j]=='0':
            b.append(s[j])
    w=min(b)
    print(w)
WA Test Cases CodeChef Solution Review:

In our experience, we suggest you solve this WA Test Cases CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the WA Test Cases CodeChef Solution

Find on CodeChef

Conclusion:

I hope this WA Test Cases CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.