You are given an array of integers, where each item in the array represents the price of a given item. You are also given an integer representing the target sale value. You must gather distinct pairs...


// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
import java.util.List;
// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
// DEFINE ANY CLASS AND METHOD NEEDED
// CLASS BEGINS, THIS CLASS IS REQUIRED
class Solution
{

// METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
int itemPairs(int num, List itemValues, int target)

{
// WRITE YOUR CODE HERE
}
// METHOD SIGNATURE ENDS
}


You are given an array of integers, where each item in the array represents the price of a<br>given item. You are also given an integer representing the target sale value. You must gather<br>distinct pairs of items that satisfy the sales target. Distinct pairs are pairs that differ in at least<br>one element.<br>Given the list of prices, write an algorithm to find the number of distinct pairs of items where<br>the sum of each pair's values is exactly equal to the target sales.<br>Input<br>The input to the function/method consists of three arguments:<br>num, an integer representing the number of items;<br>itemValues, a list of integers representing the item price;<br>target, an integer representing the target sales.<br>Output<br>Return an integer representing the number of pairs having the sum of their prices equals to<br>the target sales.<br>Constraints<br>1 s num s 5* 105<br>OsitemValues[i] s 109<br>Osi< num<br>Os target s 5* 109<br>Example<br>Input:<br>num = 9<br>

Extracted text: You are given an array of integers, where each item in the array represents the price of a given item. You are also given an integer representing the target sale value. You must gather distinct pairs of items that satisfy the sales target. Distinct pairs are pairs that differ in at least one element. Given the list of prices, write an algorithm to find the number of distinct pairs of items where the sum of each pair's values is exactly equal to the target sales. Input The input to the function/method consists of three arguments: num, an integer representing the number of items; itemValues, a list of integers representing the item price; target, an integer representing the target sales. Output Return an integer representing the number of pairs having the sum of their prices equals to the target sales. Constraints 1 s num s 5* 105 OsitemValues[i] s 109 Osi< num="" os="" target="" s="" 5*="" 109="" example="" input:="" num="">
Example<br>Input:<br>num = 9<br>itemValues = [5, 7, 9, 13, 11, 6, 6, 3, 3]<br>target = 12<br>Output:<br>3<br>Explanation:<br>There are 8 possible pairs of prices that have the sum of their values equal to the target 12.<br>(itemValues[0] = 5, itemValues[1] = 7)<br>(itemValues[1] = 7, itemValues[0] = 5)<br>(itemValues[2] = 9, itemValues[7] = 3)<br>(itemValues[7] = 3, itemValues[2] = 9)<br>(itemValues[2] = 9, itemValues[8] = 3)<br>(itemValues[8] = 3, itemValues[2] = 9)<br>(itemValues[5] = 6, itemValues[6] = 6)<br>(itemValues[6] = 6, itemValues[5] = 6)<br>%3D<br>The first two pairs are same and considered as one distinct pair. Next four pairs are same and<br>considered as one distinct pair. Similarly, last two pairs are same and considered as one<br>distinct pair.<br>There are only 3 distinct pairs of prices: (5, 7), (9, 3) and (6, 6).<br>

Extracted text: Example Input: num = 9 itemValues = [5, 7, 9, 13, 11, 6, 6, 3, 3] target = 12 Output: 3 Explanation: There are 8 possible pairs of prices that have the sum of their values equal to the target 12. (itemValues[0] = 5, itemValues[1] = 7) (itemValues[1] = 7, itemValues[0] = 5) (itemValues[2] = 9, itemValues[7] = 3) (itemValues[7] = 3, itemValues[2] = 9) (itemValues[2] = 9, itemValues[8] = 3) (itemValues[8] = 3, itemValues[2] = 9) (itemValues[5] = 6, itemValues[6] = 6) (itemValues[6] = 6, itemValues[5] = 6) %3D The first two pairs are same and considered as one distinct pair. Next four pairs are same and considered as one distinct pair. Similarly, last two pairs are same and considered as one distinct pair. There are only 3 distinct pairs of prices: (5, 7), (9, 3) and (6, 6).

Jun 01, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here