Tower Breakers – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.
Solutions of Algorithms Data Structures Hard HackerRank:
Here are all the Solutions of Hard , Advanced , Expert Algorithms of Data Structure of Hacker Rank , Leave a comment for similar posts
C++ Tower Breakers HackerRank Solution
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n,x,y;
cin>>n;
do{
cin>>x>>y;
(y==1||x%2==0)?cout<<"2"<<endl:cout<<"1"<<endl;
n--;
}while(n>0);
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
Java Tower Breakers HackerRank Solution
import java.io.*;
import java.util.*;
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 in = new Scanner(System.in);
int T = in.nextInt();
int N, M;
while (T-- > 0) {
N = in.nextInt();
M = in.nextInt();
System.out.println((M != 1 && N%2 == 1)? 1 : 2 );
}
}
}
Python 3 Tower Breakers HackerRank Solution
T = int(input())
for t in range(T):
n, m = [int(x) for x in input().strip().split()]
if m == 1:
print(2)
else:
if n % 2 == 1:
print(1)
else:
print(2)
C Tower Breakers HackerRank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d", &n);
for(int testcase = 0; testcase < n; testcase++) {
int num_towers;
int height;
scanf("%d %d", &num_towers, &height);
if(height == 1 || num_towers % 2 == 0)
printf("2\n");
else
printf("1\n");
}
return 0;
}
Leave a comment below