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

Автор loverBoUy, история, 19 месяцев назад, По-английски

Given an array. find the number of subsegments in which you can divide an array such that in the sum array of every subsegment, no two adjacent elements have the same parity;

see the test case for better understanding;

given array= [1 2 2 1] subsegment = ~~~~~ [[1],[2,2],[1]] = [[1],[4],[1]] ~~~~~

valid ,

 [[1,2,2,1]]  = [6] valid,

[[1],[2,2,1]]= [[1],[5]] not valid

hence answer is 2.

please share your approach.

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

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

Do you have a source for this problem? I think it would be helpful if we had more information on the problem, including the constraints for the size of the array

»
19 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Given your example [[1,2],[2],[1]] and [[1],[2],[1,2]] are also valid shouldn't the answer be 4?