Блог пользователя eleganc

Автор eleganc, история, 3 года назад, По-английски

Given an array of length n. The task is to make the sum of all the subarrays of length greater than two positive. To do this, you can replace any element with any integer x where -10^18 < x < 10^18. Find the minimum number of replacements needed to make the array positive.

Constraints: -10^9 < arr[i] < 10^9 and n < 10^5

Example:

Test Case 1: Arr = [-80 100 -80] Ans = 1

Test Case 2: Arr = [-10 19 -10 2] Ans = 1 (by making arr[2] = 10^18)

Полный текст и комментарии »

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

Автор eleganc, история, 3 года назад, По-английски

Given a matrix consisting of characters of the type:

  1. Single digits
  2. '-'
  3. '+'

Find the maximum value which can be evaluated using a valid expression in the matrix.

A valid expression is defined as a contiguous array:

  1. Starts from any cell with a numeric value and is either in the left to right direction or in top to bottom direction.
  2. The final expression doesn't contain any consecutive operators. Eg. '3' '+' '-' '1' is not allowed.

Example TC:

n = 7, m = 5

matrix =

'1' '+' '3' '-' '2'

'-' '2' '+' '3' '+'

'1' '-' '4' '-' '4'

'+' '2' '-' '7' '+'

'2' '+' '5' '+' '9'

'+' '1' '+' '8' '-'

'2' '-' '0' '-' '2'

Answer: 2 + 5 + 9 = 16 evaluates to the maximum value. Hence the answer is 16.

Caution: We may have a matrix like ['4' '4' '5' '-' '-' '5' '1'], in this case we are free to take 445 or 4, 5, 5, or 44 to 45

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор eleganc, история, 4 года назад, По-английски

Hi, I recently faced this problem in an OA. Any approaches to solve this?

An array consists of N elements. We want to minimize the absolute difference between adjacent elements of the array. We can change any integer to any other integer however at most K changes are allowed. If n <= 1 return 0.

Here is the exact problem link: https://www.codechef.com/CRK32020/problems/KEVIN?tab=statement There is some hint toward binary search, but I don't precisely infer how it is to be applied.

Constraints: 1 ≤ k ≤ n ≤ 2000 -1e9 ≤ Ai ≤ 1e9

Eg. N = 6, K = 3 Arr = [1 2 3 7 8 9] Here Arr can be transformed to [1 2 3 4 5 6] in 3 changes. And the answer becomes 1.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится