
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
// 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<Integer> 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
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 = 9](https://content.bartleby.com/qna-images/question/5ecf1484-f95f-4119-9858-43c8382b92c0/c25f595f-0ba7-4add-b6be-f3f5862dc33d/tgiydl_thumbnail.jpeg)
Transcribed Image 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 = 9
![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).](https://content.bartleby.com/qna-images/question/5ecf1484-f95f-4119-9858-43c8382b92c0/c25f595f-0ba7-4add-b6be-f3f5862dc33d/1yar7am_thumbnail.jpeg)
Transcribed Image 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).
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- package edu.umsl.casting;public class Main {public static void main(String[] args) {String string = "myString";Object object = new Object();object = string; // What type of casting?string = (String) object; //What type of casting?}} List the two types of casting in the above code. Group of answer choices Implicit and Explicit Generic and Exact Autoboxing and Autounboxing Closed and Openarrow_forwardUsing python: (see attached- I need help with part Q2) Add a method to the person class name it (username) that takes the email and take off all the part from @ and after, and assigns the string before the @ sign to a variable username. For example: malabdullah@UT.edu, the method will assign 'malabdullah' as the username.arrow_forwardAssume class LinkedQueue has been deńned using the implementation in your textbook that myQueue has been initialized so it is empty. Type the EXACT output of the following code segment. You may assume that the code compiles and executes without errors. LinkedQueue myQueue; int i - 1; int j = 2; int k = 3; int n = 4; myQueue.enqueue (n); myQueue.enqueue (); i = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (k); n = myQueue.peekFront (); myQueue.dequeue (); myQueue.enqueue (); myQueue.enqueue (n); while (ImyQueue.isEmpty ()) { i = myQueue.peekFront (); myQueue.dequeue (); cout << i<< " ": cout << endl;arrow_forward
- In java ****arrow_forwardPlease answer question. This is pertaining to Java programming language 3-20arrow_forwardJava Program This assignment requires one project with two classes. Class Employee Class Employee- I will attach the code for this: //Import the required packages. import java.text.DecimalFormat; import java.text.NumberFormat; //Define the employee class. class Employee { //Define the data members. private String id, lastName, firstName; private int salary; //Create the constructor. public Employee(String id, String lastName, String firstName, int salary) { this.id = id; this.lastName = lastName; this.firstName = firstName; this.salary = salary; } //Define the getter methods. public String getId() { return id; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public int getSalary() { return salary; } //Define the method to return the employee details. @Override public String toString() { //Use number format and decimal format //to…arrow_forward
- package lab1; /** * A utility class containing several recursive methods * * <pre> * * For all methods in this API, you are forbidden to use any loops, * String or List based methods such as "contains", or methods that use regular expressions * </pre> * * */ public final class Lab1 { /** * This is empty by design, Lab class cannot be instantiated */ privateLab1(){ // empty by design } /** * Returns the product of a consecutive set of numbers from <code> start </code> * to <code> end </code>. * * @param start is an integer number * @param end is an integer number * @return the product of start * (start + 1) * ..*. + end * @pre. * <code> start </code> and <code> end </code> are small enough to let * this method return an int. This means the return value at most * requires 4 bytes and no overflow would happen. */ publicstaticintproduct(ints,inte){ if(s==e){ returne; }else{ returns*product(s+1,e); } }…arrow_forwardWritten in Python with docstring please if applicable Thank youarrow_forwardpublic class OfferedCourse extends Course { // TODO: Declare private fields // TODO: Define mutator methods - // setInstructorName(), setLocation(), setClassTime() // TODO: Define accessor methods - // getInstructorName(), getLocation(), getClassTime() } import java.util.Scanner; public class CourseInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Course myCourse = new Course(); OfferedCourse myOfferedCourse = new OfferedCourse(); String courseNumber, courseTitle; String oCourseNumber, oCourseTitle, instructorName, location, classTime; courseNumber = scnr.nextLine(); courseTitle = scnr.nextLine(); oCourseNumber = scnr.nextLine(); oCourseTitle = scnr.nextLine(); instructorName = scnr.nextLine(); location = scnr.nextLine(); classTime = scnr.nextLine(); myCourse.setCourseNumber(courseNumber); myCourse.setCourseTitle(courseTitle);…arrow_forward
- // interface method ==================================================public boolean isFullBT() {/*See BST.java for method specification *//* Hint: How can you "break-up" the problem into smaller pieces? *//* Your code here */return false; // Dummy return statement. Remove when you implement!} IN JAVA LANGUAGE RETURN TRUE IF BST IS A COMPLETE BST RETURN FALSE IS BST IS NOT A COMPLETE BST ALL INFO IN PICTURES PLS AND THANK YOU!!!!!arrow_forwardProgram #11. Show the ArrayStackADT interface 2. Create the ArrayStackDataStrucClass<T> with the following methods: default constructor, overloaded constructor, copy constructor, initializeStack, isEmptyStack, isFullStack, push, peek, void pop 3. Create the PrimeFactorizationDemoClass: instantiate an ArrayStackDataStrucClass<Integer> object with 50 elements. Use a try-catch block in the main( ) using pushes/pops. 4. Exception classes: StackException, StackUnderflowException, StackOverflowException 5. Show the 4 outputs for the following: 3,960 1,234 222,222 13,780arrow_forwardpython: class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last class Course:def __init__(self):self.roster = [] # list of Student objects def add_student(self, student):self.roster.append(student) def course_size(self):return len(self.roster) # Type your code here if __name__ == "__main__":course = Course()course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robison', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) student = course.find_student_highest_gpa()print('Top student:', student.first, student.last, '( GPA:', student.gpa,')')arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education