TCS NQT HOUSES IN VILLAGE CODING PROBLEM

TCS NQT HOUSES IN VILLAGE CODING PROBLEM

TCS NQT HOUSES IN VILLAGE PROBLEM

We at gradjobopenings.com provide free job alerts of freshers job drives. In this website we list on campus job openings for freshers and off campus job openings for freshers and also work from home job openings. This is the best website to apply for off campus drive in India. Visit our website for government job alerts and private job alerts. We also list free interview notes and study materials, one of the best interview study website.comfortable to face the interviews:

There are ‘N’ number of houses in a village. Each house requires a voltage ‘V’ volts of electricity to power up their home appliances. In this context, the houses are arranged in the form of a matrix (row* columns) where ‘N’ is the order of the matrix. The amount of voltage supplied to each house is calculated as current(i) * voltage(r) where ‘i’ is the row number and ‘r’ is the column number. When the voltage supplied to the house (i * r) matches the value ‘V’, the appliances in the house can work. The task here is to find the number of houses whose voltage value(i*r) is the same as ‘V’. If none of the house’s value matches display a message “NO POWER”.

**Input format**

– First line: N, a non-negative integer.

– Second line: V, a non-negative integer.

**Example 1:**

– Input:

  – 5     -> Value of N i.e. rows, columns=5

  – 15    -> Value of V

– Output :

  – 2     -> number of houses whose i*r value matches

– Explanation:

  – From the inputs given above, i=5, r=5, the below table represents values (i*r):

“`

+=====+===+====+====+====+====+

| i/j | 1 |  2 |  3 |  4 |  5 |

+—–+—+—-+—-+—-+—-+

|  1  | 1 |  2 |  3 |  4 |  5 |

+—–+—+—-+—-+—-+—-+

|  2  | 2 |  4 |  6 |  8 | 10 |

+—–+—+—-+—-+—-+—-+

|  3  | 3 |  6 |  9 | 12 | 15 |

+—–+—+—-+—-+—-+—-+

|  4  | 4 |  8 | 12 | 16 | 20 |

+—–+—+—-+—-+—-+—-+

|  5  | 5 | 10 | 15 | 20 | 25 |

+=====+===+====+====+====+====+

“`

  – From the table above, we can deduce that the value v=15 occurs only in the houses (3,5) (5,3). Hence, the output is 2.

**Example 2:**

– Input:

  – 3     -> Value of N i.e. rows, columns = 3

  – 10    -> Value of V

– Output :

  – NO POWER

– Explanation:

  – From the inputs given above, i = 3, r = 3, the below table represents values (i*r):

“`

+=====+===+====+====+

| i/j | 1 |  2 |  3 |

+—–+—+—-+—-+

|  1  | 1 |  2 |  3 |

+—–+—+—-+—-+

|  2  | 2 |  4 |  6 |

+—–+—+—-+—-+

|  3  | 3 |  6 |  9 |

+=====+===+====+====+

“`

– From the table above, we can deduce that the value v=10 doesn’t match with the voltage in any of the houses. Hence, the output is NO POWER

**Constraints:**

– 0 < N <= 50

– 0 < V <= 250

Program in C

#include <stdio.h>

int main() {
    int n, v, count = 0;
    scanf("%d%d", &n, &v);
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= n ; j++)
            if( i * j == v )
                count++;
    if(count == 0)
        printf("NO POWER");
    else
        printf("%d", count);
    return 0;
}

Program in C++

#include <iostream>

int main() {
    int n, v, count = 0;
    std::cin >> n >> v;
    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= n ; j++)
            if( i * j == v )
                count++;
    if(count == 0)
        printf("NO POWER");
    else
        std::cout << count;
    return 0;
}

Program in Java

import java.util.*;
class Main
{
     public static void main(String[] args)
     {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int v = in.nextInt();
        in.close();
        int count = 0;
        for(int i = 1 ; i <= n ; i++)
            for(int j = 1 ; j <= n ; j++)
                if( i * j == v )
                    count++;
        if(count == 0)
            System.out.print("NO POWER");
        else
            System.out.print(count);
    }
}

Program in Python

if __name__ == '__main__':
    n = int(input())
    v = int(input())
    count = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i * j == v:
                count += 1
    if count == 0:
        print("NO POWER", end='')
    else:
        print(count, end='')

FOR MORE TCS NQT CODING QUESTIONS 👉👉👉👉 CLICK HERE

1 thought on “TCS NQT HOUSES IN VILLAGE CODING PROBLEM”

  1. Pingback: TCS NQT CODING QUESTIONS WITH SOLUTIONS - GRAD JOB OPENINGS

Leave a Comment

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

error: Content is protected !!