< Summary

Information
Class: LeetCode.Algorithms.SortingTheSentence.SortingTheSentenceIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortingTheSentence\SortingTheSentenceIterative.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 40
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SortSentence(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SortingTheSentence\SortingTheSentenceIterative.cs

#LineLine coverage
 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
 12namespace LeetCode.Algorithms.SortingTheSentence;
 13
 14/// <inheritdoc />
 15public class SortingTheSentenceIterative : ISortingTheSentence
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n + m * l), where n is the length of the input string, m is the number of words, and l i
 19    ///     the average length of these words. Since n is essentially m * l (each character in the input string is part
 20    ///     of a word), the time complexity simplifies to O(n)
 21    ///     Space complexity - O(m), where m is the number of words
 22    /// </summary>
 23    /// <param name="s"></param>
 24    /// <returns></returns>
 25    public string SortSentence(string s)
 226    {
 227        var wordsWithIndexes = s.Split(' ');
 28
 229        var words = new string[wordsWithIndexes.Length];
 30
 2231        foreach (var wordsWithIndex in wordsWithIndexes)
 832        {
 833            var index = (int)char.GetNumericValue(wordsWithIndex.Last()) - 1;
 34
 835            words[index] = wordsWithIndex[..^1];
 836        }
 37
 238        return string.Join(' ', words);
 239    }
 40}

Methods/Properties

SortSentence(System.String)