0% found this document useful (0 votes)
10 views

QuestionsList

Uploaded by

Singh Dhirendra
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

QuestionsList

Uploaded by

Singh Dhirendra
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Given a package with a weight limit limit and an array arr of item weights,

implement a function getIndicesOfItemWeights that finds two items whose sum of


weights equals the weight limit limit. Your function should return a pair [i, j] of
the indices of the item weights, ordered such that i > j. If such a pair doesn't
exist, return an empty array.

Analyze the time and space complexities of your solution.

Example:

input: arr = [4, 6, 10, 15, 16], lim = 21

output: [3, 1] # since these are the indices of the


# weights 6 and 15 whose sum equals to 21

// Write your code here.


static int[] getIndicesOfItemWeights(int[] arr, int limit) {

Given an array arr of distinct integers and a nonnegative integer k, write a


function findPairsWithGivenDifference that returns an array of all pairs [x,y] in
arr, such that x - y = k. If no such pairs exist, return an empty array.

Note: the order of the pairs in the output array should maintain the order of the y
element in the original array.

Examples:

input: arr = [0, -1, -2, 2, 1], k = 1


output: [[1, 0], [0, -1], [-1, -2], [2, 1]]

input: arr = [1, 7, 5, 3, 32, 17, 12], k = 17


output: []

int[][] findPairsWithGivenDifference(int[] arr, int k) {

Validate an IP address (IPv4). An address is valid if and only if it is in the form


"X.X.X.X", where each X is a number from 0 to 255.

For example, "12.34.5.6", "0.23.25.0", and "255.255.255.255" are valid IP


addresses, while "12.34.56.oops", "1.2.3.4.5", and "123.235.153.425" are invalid IP
addresses.

Examples:

ip = '192.168.0.1'
output: true

ip = '0.0.0.0'
output: true

ip = '123.24.59.99'
output: true

ip = '192.168.123.456'
output: false

boolean validateIP(String ip) {

You might also like