BudiBadu Logo

Parity Flag Map

Array Easy 0 views
Like7

You are reviewing a sequence of sensor readings represented by integers. To help the operations team spot stable points quickly, you need to create a boolean map that marks whether each reading is even. An even reading corresponds to a calm moment, while an odd reading marks a fluctuation. Your task is to examine the input array and build a parallel array of booleans where each position contains true if the corresponding number is even and false otherwise.

Think of it as placing flags along a trail. Every time you encounter an even number, you plant a green flag, and for odd numbers you plant a red flag. The final output is the row of flags in order, telling the team exactly which checkpoints are calm without altering the original data. Empty input should return an empty array of flags, and negative numbers still follow the same even-or-odd rule based on divisibility by two.

This challenge focuses on mapping values to simplified indicators. By returning a boolean array, you create a quick reference for analysts to scan, making it easy to spot patterns like consecutive periods of calm or alternating spikes and lows.

Example 1:

Input: nums = [2,5,6,3]
Output: [true,false,true,false]
Explanation: Even numbers (2,6) produce true entries.

Example 2:

Input: nums = [1,3,5]
Output: [false,false,false]
Explanation: All numbers are odd.

Example 3:

Input: nums = []
Output: []
Explanation: No readings mean no flags.

Algorithm Flow

Recommendation Algorithm Flow for Parity Flag Map - Budibadu
Recommendation Algorithm Flow for Parity Flag Map - Budibadu

Best Answers

java
import java.util.stream.IntStream;
class Solution {
    public Object parity_flags(Object nums) {
        int[] arr = (int[]) nums;
        return IntStream.of(arr).map(n -> n % 2).toArray();
    }
}