Hiring Test solution – A company conducted a coding test to hire candidates. 2N candidates appeared for the test

Hiring Test solution

Hiring Test solution

A company conducted a coding test to hire candidates. NN candidates appeared for the test, and each of them faced MM problems. Each problem was either unsolved by a candidate (denoted by ‘U’), solved partially (denoted by ‘P’), or solved completely (denoted by ‘F’).

To pass the test, each candidate needs to either solve XX or more problems completely, or solve (X1)(X−1) problems completely, and YY or more problems partially.

Given the above specifications as input, print a line containing NN integers. The ithith integer should be 11 if the ithith candidate has passed the test, else it should be 00.

Input: Hiring Test solution

  • The first line of the input contains an integer TT, denoting the number of test cases.
  • The first line of each test case contains two space-separated integers, NN and MM, denoting the number of candidates who appeared for the test, and the number of problems in the test, respectively.
  • The second line of each test case contains two space-separated integers, XX and YY, as described above, respectively.
  • The next NN lines contain MM characters each. The jthjth character of the ithith line denotes the result of the ithith candidate in the jthjth problem. ‘F’ denotes that the problem was solved completely, ‘P’ denotes partial solve, and ‘U’ denotes that the problem was not solved by the candidate.

Hiring Test solution

Output: Hiring Test solution

For each test case, print a single line containing NN integers. The ithith integer denotes the result of the ithith candidate. 11 denotes that the candidate passed the test, while 00 denotes that he/she failed the test.

Constraints : Hiring Test solution

  • 1T1001≤T≤100
  • 1N1001≤N≤100
  • 2M1002≤M≤100
  • 1X,YM1≤X,Y≤M
  • 1(X1)+YM1≤(X−1)+Y≤M

Sample Input: Hiring Test solution

3
4 5
3 2
FUFFP
PFPFU
UPFFU
PPPFP
3 4
1 3
PUPP
UUUU
UFUU
1 3
2 2
PPP

Sample Output: Hiring Test solution

1100
101
0

Explanation: Hiring Test solution

  • Sample Test 1: There are 44 candidates and 55 problems. Each candidate needs to solve 33 or more problems completely, or 22 problems completely and 22 or more problems partially. Only the first and the second candidates satisfy this.

  • Sample Test 2: The candidates need to either solve at least one problem completely, or they need to solve three or more problems partially. Only candidates 11 and 33 satisfy this.

  • Sample Test 3: The candidate needs to either solve two or more problems completely, or solve at least one problems completely and two problems partially. The candidate does not satisfy this.

Hiring Test solution

Program Code : Hiring Test solution

C++

// #pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
// #define mp make_pair
#define pii pair<int,int>
// #define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
vector<string> split(const string& s, char c) {
vector<string> v; stringstream ss(s); string x;
while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
stringstream s; s << "[";
for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
s << arr[n - 1] << "]";
return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
__evars_out_var(a);
cerr << "; ";
__evars(++it, args...);
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());

for (int i = start; i < end; i++)
cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}

size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T> istream& operator >>(istream &in,vector<T> &v){
for(auto &x:v) in>>x; return in;
}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){
for(auto &x:v) out<<x<<' '; return out;
}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){
in>>p.first>>p.second; return in;
}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){
out<<p.first<<' '<<p.second; return out;
}
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
map<pair<ll,ll>, bool> vis;
ll n, m;
ll cnt = 0;
vector<string> mat;
bool isSafe(ll x, ll y)
{
if(x >= 0 && x < n && y >= 0 && y < m)
return true;
else
return false;
}
void dfs(ll x, ll y)
{
cnt++;
vis[{x, y}] = true;
// cout << x << " " << y << endl;
// cout << cnt << endl;
if(isSafe(x + 1, y) && !vis[{x + 1, y}] && mat[x + 1][y] == '1')
dfs(x + 1, y);
if(isSafe(x - 1, y) && !vis[{x - 1, y}] && mat[x - 1][y] == '1')
dfs(x - 1, y);
if(isSafe(x, y - 1) && !vis[{x, y - 1}] && mat[x][y - 1] == '1')
dfs(x, y - 1);
if(isSafe(x, y + 1) && !vis[{x, y + 1}] && mat[x][y + 1] == '1')
dfs(x, y + 1);
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
clock_t clk = clock();
int t = 1;
cin >> t;
rep(tc, t)
{
// cout << "Case #" << tc + 1 << ": ";
ll n, m, x, y;
cin >> n >> m >> x >> y;
string ans;
for(int i = 0; i < n; i++)
{
map<char, ll> m;
string s;
cin >> s;
for(char c: s)
m[c]++;
if(m['F'] >= x || (m['F'] == (x - 1) && m['P'] >= y))
ans += '1';
else
ans += '0';
}
cout << ans << endl;
} 
cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n'; 
}

JAVA

//Some of the methods are copied from GeeksforGeeks Website 
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{ 
//static Reader sc=new Reader();
static FastReader sc=new FastReader(System.in);
static boolean valid(String s)
{
long u=0,p=0,f=0;
for(char c : s.toCharArray())
{
if(c=='F')
f++;
if(c=='P')
p++;
}
if(f>=x) return true;
if(f>=x-1 && p>=y) return true;
return false;
}
static long x=0;
static long y=0;
public static void main (String[] args) throws java.lang.Exception
{
try{
/*
int n=sc.nextInt();
ArrayList<Integer> al=new ArrayList<>();
ArrayList<Long> al=new ArrayList<>();
Set<Integer> set=new HashSet<>();
Collections.sort(al,Collections.reverseOrder());

long n=sc.nextLong();
for(int i=0;i<n;i++) 
String s=sc.next();
*/
int t = sc.nextInt();

while(t-->0)
{ 
StringBuilder sb=new StringBuilder();
long n=sc.nextLong();
long m=sc.nextLong();
x=sc.nextLong();
y=sc.nextLong();
for(int i=0;i<n;i++)
{
String s=sc.next();
boolean pass=valid(s);

if(pass)
sb.append("1");
else
sb.append("0");
}
out.println(sb);
}
out.flush();
out.close();
} 
catch(Exception e)
{}
}

/*
...SOLUTION ENDS HERE...........SOLUTION ENDS HERE...
*/

static void flag(boolean flag)
{
out.println(flag ? "YES" : "NO");
out.flush();
}

/* 
Map<Long,Long> map=new HashMap<>();
for(int i=0;i<n;i++)
{
if(!map.containsKey(a[i]))
map.put(a[i],1);
else
map.replace(a[i],map.get(a[i])+1);
}

Set<Map.Entry<Long,Long>> hmap=map.entrySet();
for(Map.Entry<Long,Long> data : hmap)
{

}

Iterator<Integer> it = set.iterator();
while(it.hasNext()) 
{ 
int x=it.next();
}
*/

static void print(int a[])
{
int n=a.length;
for(int i=0;i<n;i++)
{
out.print(a[i]+" ");
}
out.println();
out.flush();
}
static void print(long a[])
{
int n=a.length;
for(int i=0;i<n;i++)
{
out.print(a[i]+" ");
}
out.println();
out.flush();
} 
static void print_int(ArrayList<Integer> al)
{
int si=al.size();
for(int i=0;i<si;i++)
{
out.print(al.get(i)+" ");
}
out.println();
out.flush();
}
static void print_long(ArrayList<Long> al)
{
int si=al.size();
for(int i=0;i<si;i++)
{
out.print(al.get(i)+" ");
}
out.println();
out.flush();
}

static class Graph
{
int v;
ArrayList<Integer> list[];
Graph(int v)
{
this.v=v;
list=new ArrayList[v+1];
for(int i=1;i<=v;i++)
list[i]=new ArrayList<Integer>();
}
void addEdge(int a, int b)
{
this.list[a].add(b);
}
}
static void DFS(Graph g, boolean[] visited, int u)
{
visited[u]=true;
int v=0;
for(int i=0;i<g.list[u].size();i++)
{
v=g.list[u].get(i);
if(!visited[v])
DFS(g,visited,v);
}
} 

// static class Pair
// {
// int x,y;
// Pair(int x,int y)
// {
// this.x=x;
// this.y=y;
// }
// }

static long sum_array(int a[])
{
int n=a.length;
long sum=0;
for(int i=0;i<n;i++)
sum+=a[i];
return sum;
}
static long sum_array(long a[])
{
int n=a.length;
long sum=0;
for(int i=0;i<n;i++)
sum+=a[i];
return sum;
}

static void sort(int[] a) 
{
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void sort(long[] a) 
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}

static void reverse_array(int a[])
{
int n=a.length;
int i,t; 
for (i = 0; i < n / 2; i++) { 
t = a[i]; 
a[i] = a[n - i - 1]; 
a[n - i - 1] = t; 
} 
}
static void reverse_array(long a[])
{
int n=a.length;
int i; long t; 
for (i = 0; i < n / 2; i++) { 
t = a[i]; 
a[i] = a[n - i - 1]; 
a[n - i - 1] = t; 
} 
}

static long gcd(long a, long b) 
{ 
if (a == 0) 
return b; 

return gcd(b%a, a); 
} 
static int gcd(int a, int b) 
{ 
if (a == 0) 
return b; 

return gcd(b%a, a); 
}

static class FastReader{

byte[] buf = new byte[2048];
int index, total;
InputStream in;

FastReader(InputStream is) {
in = is;
}

int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}

String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan());
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}

int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}

long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}

static class Reader 
{ 
final private int BUFFER_SIZE = 1 << 16; 
private DataInputStream din; 
private byte[] buffer; 
private int bufferPointer, bytesRead; 

public Reader() 
{ 
din = new DataInputStream(System.in); 
buffer = new byte[BUFFER_SIZE]; 
bufferPointer = bytesRead = 0; 
} 

public Reader(String file_name) throws IOException 
{ 
din = new DataInputStream(new FileInputStream(file_name)); 
buffer = new byte[BUFFER_SIZE]; 
bufferPointer = bytesRead = 0; 
} 

public String readLine() throws IOException 
{ 
byte[] buf = new byte[64]; // line length 
int cnt = 0, c; 
while ((c = read()) != -1) 
{ 
if (c == '\n') 
break; 
buf[cnt++] = (byte) c; 
} 
return new String(buf, 0, cnt); 
} 

public int nextInt() throws IOException 
{ 
int ret = 0; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 
do
{ 
ret = ret * 10 + c - '0'; 
} while ((c = read()) >= '0' && c <= '9'); 

if (neg) 
return -ret; 
return ret; 
} 

public long nextLong() throws IOException 
{ 
long ret = 0; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 
do { 
ret = ret * 10 + c - '0'; 
} 
while ((c = read()) >= '0' && c <= '9'); 
if (neg) 
return -ret; 
return ret; 
} 

public double nextDouble() throws IOException 
{ 
double ret = 0, div = 1; 
byte c = read(); 
while (c <= ' ') 
c = read(); 
boolean neg = (c == '-'); 
if (neg) 
c = read(); 

do { 
ret = ret * 10 + c - '0'; 
} 
while ((c = read()) >= '0' && c <= '9'); 

if (c == '.') 
{ 
while ((c = read()) >= '0' && c <= '9') 
{ 
ret += (c - '0') / (div *= 10); 
} 
} 

if (neg) 
return -ret; 
return ret; 
} 

private void fillBuffer() throws IOException 
{ 
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
if (bytesRead == -1) 
buffer[0] = -1; 
} 

private byte read() throws IOException 
{ 
if (bufferPointer == bytesRead) 
fillBuffer(); 
return buffer[bufferPointer++]; 
} 

public void close() throws IOException 
{ 
if (din == null) 
return; 
din.close(); 
} 
}
static PrintWriter out=new PrintWriter(System.out);
static int int_max=Integer.MAX_VALUE;
static int int_min=Integer.MIN_VALUE;
static long long_max=Long.MAX_VALUE;
static long long_min=Long.MIN_VALUE;
}
// Thank You !

PYTHON

for tc in range(int(input())):
N, M = map(int, input().split())
X, Y = map(int, input().split())
for i in range(N):
S = input()
if S.count("F") >= X or (S.count("F") >= X - 1 and S.count("P") >= Y):
print('1', end = '')
else:
print("0", end = '')
print()

Hiring Test solution

Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution, Hiring Test solution,

Also read : Flower Sequence solution codechef 2021

Leave a Comment