Nutanix 欧哎

之前投了一个Nutanix的实习,上来就要做OA,分享一下

第一题,
已知一个array包含 0 和 1,求它的weight
定义:
Weight of string = Weight of total pairs + weight of single characters - Total number of toggles.Two consecutive characters are considered as pair only if they are different. Weight of a single pair (both character are different) = 4Weight of a single character = 1
举例:
input = ‘‘00’’
weight = one pair - one toggle = 4-1=3

input = ‘‘011’’ (可以转变任意数量的0->1 或者 1->0 使之最大化)
weight = one pair + one character = 4 + 1 = 5

读到这里觉得很屌,感觉是挺难的,结果目标函数的输入里面包括了 pair分数,toggle 分数 和 转变分数,一个公式就解决了。

第二题,
给一个array of non negative integers, 每一个位置代表青蛙从这个位置能跳跃的最大距离
求青蛙从最左边跳到最右边要最少几步?
举例:
[1, 2, 1, 3, 0, 4, 1, 2, 1]
index 0, 1, 2, 3, 4, 5, 6, 7, 8
青蛙 跳跃位置index : 0, 1, 3, 5, 8 , 四步