| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.SpecialArray2; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class SpecialArray2BruteForce : ISpecialArray2 |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Time complexity - O(m * n) |
| | 19 | | /// Space complexity - O(m) |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="nums"></param> |
| | 22 | | /// <param name="queries"></param> |
| | 23 | | /// <returns></returns> |
| | 24 | | public bool[] IsArraySpecial(int[] nums, int[][] queries) |
| 2 | 25 | | { |
| 2 | 26 | | var result = new bool[queries.Length]; |
| | 27 | |
|
| 10 | 28 | | for (var i = 0; i < queries.Length; i++) |
| 3 | 29 | | { |
| 3 | 30 | | result[i] = IsArraySpecial(nums, queries[i][0], queries[i][1]); |
| 3 | 31 | | } |
| | 32 | |
|
| 2 | 33 | | return result; |
| 2 | 34 | | } |
| | 35 | |
|
| | 36 | | private static bool IsArraySpecial(int[] nums, int start, int end) |
| 3 | 37 | | { |
| 16 | 38 | | for (var i = start; i < end; i++) |
| 7 | 39 | | { |
| 7 | 40 | | if (nums[i] % 2 == nums[i + 1] % 2) |
| 2 | 41 | | { |
| 2 | 42 | | return false; |
| | 43 | | } |
| 5 | 44 | | } |
| | 45 | |
|
| 1 | 46 | | return true; |
| 3 | 47 | | } |
| | 48 | | } |