zuloochallenge.blogg.se

Infosys apple java questions
Infosys apple java questions







infosys apple java questions

Each line i of the N subsequent lines(where 0The next line contains an integer, k, denoting the maximum value of x.The first line contains integer N denoting the number of elements in A.Xor-sum(x)=(x XOR A)+(x XOR A)+(x XOR A)+………….+(x XOR A)Ĭan you find the integer x in the range with the maximum Xor-sum (x) value?.Resil wrote down an array A of length N, an integer K and he defined a new function called Xor- sum as follows Wael is well-known for how much he loves the bitwise XOR operation, while kaito is well known for how much he loves to sum numbers, so their friend Resli decided to make up a problem that would enjoy both of them. N=3 X=1 Y=1 A= The optimal solution is to perform one operation of the first type on the subarray

infosys apple java questions

The optimal solution is to perform one operation of the first type on the subarray.

  • Each line i of the N subsequent lines (where 1 <=i<= N) contains an Integer describing Ai.
  • Y, denoting the cost of the second operation
  • The next line contains an integer, X, denoting the cost of the first operation.
  • The first line contains an integer, N., denoting the number of elements in A.
  • Your task is to make all the elements equal to 0 and find the minimum cost to do so. – Choosing an index i such that A is positive, and setting A = 0. – Choosing a subarray and subtracting 1 from each element in this subarray. Given an array A of N elements, you can apply the following operations as many times as you like: It is optimal to put the first two gifts in the first box, and all the rest in the second There are two distinct types in the first box, and three in the second box then, so the total value is 5.Ī subarray of array A is a segment of contiguous elements in array A. Wael has only one box he has to put all gifts in it, so that there are two types of gifts in the box, so the value is equal to 2 Wael will put the only gift in a box so the total value will be 1.
  • Each line i of the N subsequent lines (where 0≤i
  • The next line contains an integer, K, denoting the number of boxes.
  • The first line contains an integer, N, denoting the number of elements in A.
  • Each gift should be put in exactly one box, and each box should contain a sub-array of consecutive gifts.
  • Your task is to help him determine this maximum possible total value Wael wants to maximize the total value of all boxes with gifts. Wael wants to pack exactly K boxes, and he has to put in each box a sub-array of consecutive gifts

    infosys apple java questions

    Wael has N gifts, such that the type of each gift i is A. Let’s define the Value of the box as the number of distinct types of gifts inside this box. He decided to pack the gifts in boxes and give each child a box. Problem Statement : Wael wants to play Santa this year, so he prepared gifts for all the children of the neighborhood.

    infosys apple java questions

    Void solve(int l, int r, int L1, int R1, int now)įor (i = 1 i <= n ++i) dp = inf, pre = lst], lst] = i įor (i = 1 i <= n ++i) lst] = n + 1 įor (i = n i -i) nxt = lst], lst] = i įor (i = 1 i <= m ++i) solve(1, n, 0, n, i) Int a, dp, lst, pre, nxt, i, j, n, m, L, R, sum Total cost would be 1+2=3Ĭonst int N = 4e5, M = 110, inf = 0x3f3f3f3f We can divide the array into and Cost of will be (1-1)+(3-2)+(4-4)=1 and cost of will be 3-1=2. The only possible segment is The cost is 1-1=0 Each line i of the n subsequent lines (where 0 The next line contains an integer, k, denoting the Number of required consecutive segments.The first line contains an integer, n, denoting the number of elements in a.Your task is to find the minimum possible total sum of the cost of all segments. We define the cost of some segment t as the sum of distances between the first and last occurrence for each unique element in the segment t. You are given an array a of N Integers and asked to split the array a into k consecutive segments such that each element of a belongs to exactly one segment and the sum of the cost of all segments is minimum.









    Infosys apple java questions