Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя sonusingh.nitaa

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

I am trying to solve this problem on Hackerrank.

https://www.hackerrank.com/challenges/the-strange-function/problem

I am not able to understand how to quickly find: (sum of subarray) — (maximum of subarray)

Please anyone explain how to solve this. Thanks in advance

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For find out the sum of a subarray you can use cumulative sum technique. Sum of subarray [l, r] is cumulativesum[r] — cumulativesum[l-1].

Maximum of a subarray can be easily found by segment tree data structure.