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

Автор wish_me, история, 7 лет назад, По-английски

Given an array of n integers. Find the maximum value of arr[i] mod arr[j] where arr[i] >= arr[j] and 1 <= i, j <= n

where arr.size<10^3 n<10^3

Input: arr[] = {3, 4, 7}

Output: 3

Explanation:

There are 3 pairs which satisfies arr[i] >= arr[j] are:-

4, 3 => 4 % 3 = 1

7, 3 => 7 % 3 = 1

7, 4 => 7 % 4 = 3

Hence Maximum value among all is 3.

Input: arr[] = {3, 7, 4, 11}

Output: 4

Input: arr[] = {4, 4, 4}

Output: 0

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