DEV Community

Gourav Kadu
Gourav Kadu

Posted on

4 1

Wipro Coding Question "Company Target Sale "

An apparel company has a list of sales rates of N items from its website. Each item is labeled with a unique ID from 0 to N-1. The company has a target sales rate, say K. The company wishes to know the two items whose total sales rate is equal to the target sales rate. The list of sales is prepared in such a way that no more than two items' total sales rate will be equal to the target rate.

Write an algorithm to find the ID of the items whose total sales value is equal to the given target value.

Input:-
The first line of input consists of two space separated integers-numitems and target, representing the total number of selected items (N) and the selected target sales rate(K), The second line of input consists of N space-separated integers- item[0], item[1],item[2]................item[N-1]. representing the sales rate of the selected items.

Output:-

Print two space-separated integers representing the ID of the items whose total sales rate is equal to the given target rate. If no such item exists then print-1.

Constraints

0 ≤ numitems ≤ 10^6

-10^6 ≤ items ≤ 10^6

O ≤ i ≤ numitems

Example

Input:

5 14

6 5 3 11 10
Enter fullscreen mode Exit fullscreen mode

Output:

2 3
Enter fullscreen mode Exit fullscreen mode

Explanation

The ID of two items with a total sales rate of 14 are 2 & 3 (3+11-14).

Solution:-
To run the code Click here

import java.util.*;
public class Main
{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int num = sc.nextInt();
        int arr[] = new int[n];

        for(int i=0; i < n; i++){
            arr[i]= sc.nextInt();
        }
        for(int i=0;i<n-1;i++){
        for(int j =i+1; j<n-1; j++){
            if(arr[i]+arr[j]== num){
                System.out.println(i+" "+j);
            }

        }
    }

    }
}


Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (1)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs