| | | 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.DesignAnOrderedStream; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class DesignAnOrderedStreamArray : IDesignAnOrderedStream |
| | | 16 | | { |
| | | 17 | | private readonly string?[] _stream; |
| | | 18 | | private int _pointer; |
| | | 19 | | |
| | 1 | 20 | | public DesignAnOrderedStreamArray(int n) |
| | 1 | 21 | | { |
| | 1 | 22 | | _stream = new string[n]; |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Time complexity - O(n) |
| | | 27 | | /// Space complexity - O(n) |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="idKey"></param> |
| | | 30 | | /// <param name="value"></param> |
| | | 31 | | /// <returns></returns> |
| | | 32 | | public IList<string?> Insert(int idKey, string value) |
| | 5 | 33 | | { |
| | 5 | 34 | | var result = new List<string?>(); |
| | | 35 | | |
| | 5 | 36 | | _stream[idKey - 1] = value; |
| | | 37 | | |
| | 10 | 38 | | while (_pointer < _stream.Length && _stream[_pointer] != null) |
| | 5 | 39 | | { |
| | 5 | 40 | | result.Add(_stream[_pointer]); |
| | | 41 | | |
| | 5 | 42 | | _pointer++; |
| | 5 | 43 | | } |
| | | 44 | | |
| | 5 | 45 | | return result; |
| | 5 | 46 | | } |
| | | 47 | | } |