01.02.2025
Join me on Telegram
Problem TLDR
All siblings even-odd #easy
Intuition
Let's golf
Approach
there is also a bitmask solution for i128 ints: only two masks possible
010101...
and101010...
can you make it shorter?
Complexity
Time complexity: $$O(n)$$
Space complexity: $$O(1)$$ O(n) for Kotlin golf
Code
fun isArraySpecial(nums: IntArray) = Regex("0, 0|1, 1") !in "${nums.map { it % 2 }}"
pub fn is_array_special(nums: Vec<i32>) -> bool { (1..nums.len()).all(|i| nums[i] % 2 != nums[i - 1] % 2) }
bool isArraySpecial(vector<int>& n) { int r = 1; for(int i = size(n); --i; r &= n[i] % 2 ^ n[i - 1] % 2); return r; }