#3618
Split Array by Prime Indices
medium · 49.3% accepted · 54 likes · top 36%
array · math · number theory
Description
You are given an integer array nums.
Split nums into two arrays A and B using the following rule:
- Elements at prime indices in nums must go into array A.
- All other elements must go into array B.
Return the absolute difference between the sums of the two arrays: |sum(A) - sum(B)|.
Note: An empty array has a sum of 0.
Solution