| | | 1 | | // -------------------------------------------------------------------------------- |
| | | 2 | | // Copyright (C) 2026 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.FindAllKDistantIndicesInAnArray; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class FindAllKDistantIndicesInAnArrayBruteForce : IFindAllKDistantIndicesInAnArray |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Time complexity - O(n^2) |
| | | 19 | | /// Space complexity - O(1) |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="nums"></param> |
| | | 22 | | /// <param name="key"></param> |
| | | 23 | | /// <param name="k"></param> |
| | | 24 | | /// <returns></returns> |
| | | 25 | | public IList<int> FindKDistantIndices(int[] nums, int key, int k) |
| | 2 | 26 | | { |
| | 2 | 27 | | var result = new List<int>(); |
| | | 28 | | |
| | 28 | 29 | | for (var i = 0; i < nums.Length; ++i) |
| | 12 | 30 | | { |
| | 86 | 31 | | for (var j = 0; j < nums.Length; ++j) |
| | 42 | 32 | | { |
| | 42 | 33 | | if (nums[j] != key || Math.Abs(i - j) > k) |
| | 31 | 34 | | { |
| | 31 | 35 | | continue; |
| | | 36 | | } |
| | | 37 | | |
| | 11 | 38 | | result.Add(i); |
| | | 39 | | |
| | 11 | 40 | | break; |
| | | 41 | | } |
| | 12 | 42 | | } |
| | | 43 | | |
| | 2 | 44 | | return result; |
| | 2 | 45 | | } |
| | | 46 | | } |