Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
In Chefland, there are N houses numbered from 1 to N, i^ith house has a defence system having strength Ai.
Chef suspects a bomb drop on one of the houses very soon. A bomb with attack strength X can destroy the i^ith house, if the defence system of the i^ith house Ai, is strictly less than X.
Also, when the i^ith house is destroyed due to the bomb, all houses with indices j such that 1≤j<i get destroyed as well irrespective of their defence system.
Given one bomb with attack strength X, find the maximum number of houses that can get destroyed.
For each test case, output in a single line the maximum number of houses that can get destroyed if the bomb can hit any house.
Input:
2
8 6
4 1 6 1 6 5 6 8
2 1
3 5
Output:
6
0
Test Case 1: The bomb can only destroy houses 1,2,4, and 6.
The maximum number of destroyed houses is 6.
Test Case 2: The bomb cannot destroy any of the houses as the defence system of each house is not lesser than attack power of bomb. Thus, the total number of destroyed houses is 0.
# cook your dish here
for i in range(int(input())):
a,b=map(int,input().split())
l=list(map(int,input().split()))
count=0
for i in range(len(l)):
if(b>l[i]):
count = i+1
print(count)
/* 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
Scanner in=new Scanner(System.in);
int te=in.nextInt();
while(te-->0){
int n=in.nextInt();
int k=in.nextInt();
int ar[]=new int[n];
int res=-1;
for(int i=0;i<n;i++){
ar[i]=in.nextInt();
if(ar[i]<k)
res=i+1;
}
if(res==-1)
System.out.println(0);
else
System.out.println(res);
}
}
}
#include <iostream>
using namespace std;
int main() {
int t; cin >> t;
while(t--){
int n,x,index = 0; cin >> n >> x;
int arr[n];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = 0; i < n; i++){
if(x > arr[i]){
index = i+1;
}
}
cout << index << endl;
}
return 0;
}
In our experience, we suggest you solve this Bomb the base 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 Bomb the base CodeChef Solution
I hope this Bomb the base 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 >>