Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Bomb the base CodeChef Solution

Problem – Bomb the base CodeChef Solution

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.

Input Format

  • The first line will contain T – the number of test cases. Then the test cases follow.
  • First line of each test case contains 2 integers N,X.
  • Second line of test case contains N space separated integers A1​,A2​,…,AN​.

Output Format

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.


  • 1≤T≤100
  • 1≤N≤10^5
  • 1≤X≤10^9
  • 1≤Ai​≤10^9
  • Sum of N over all test cases does not exceed 10^5

Sample 1:

8 6
4 1 6 1 6 5 6 8
2 1
3 5


Test Case 1: The bomb can only destroy houses 1,2,4, and 6.

  • If it hits house 1, only house 1 is destroyed.
  • If it hits house 2, houses 1 and 2 are destroyed.
  • If it hits house 4, houses 1,2,3 and 44 are destroyed.
  • If it hits house 6, houses 1,2,3,4,5, and 6 are destroyed.

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.

Bomb the base CodeChef Solution in Pyth 3

# cook your dish here
for i in range(int(input())):
    for i in range(len(l)):
            count = i+1

Bomb the base CodeChef Solution in Java

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

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

/* 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(;
		int te=in.nextInt();
		    int n=in.nextInt();
		    int k=in.nextInt();
		    int ar[]=new int[n];
		    int res=-1;
		    for(int i=0;i<n;i++){

Bomb the base CodeChef Solution in C++14

#include <iostream>
using namespace std;

int main() {
	int t; cin >> 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;
Bomb the base CodeChef Solution Review:

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

Find on CodeChef


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 >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *