Gready Approach
How it workQuestion in ProblemsReturn smallest lexicographically string after operaton. We will have answer which have first occurance letter which is not 'a' s
# How it work

## Question in Problems
Return smallest lexicographically string after operaton. We will have answer which have first occurance letter which is not 'a' symbol. Because If we have 'a' symbol then we need skip him.

Thefore We need find subtring in string which not have symbols 'a'. We change each symbol in substing and return our answer. EASY. 

## Greedy
This Approach must be greedy in each iteration algorithm. It'a important. We be greedy in each step -> Therefore we get optimal solution after evaluate. 

## Cases
1. If have string size == 1. We check if it's 'a' then we return 'z else we return sybmbol - 1.
2. If All symbol be 'a' -> We have this string "**aaaaaaaaaaa**" -> then valid answer be "**aaaaaaaaaaz**" -> because we must substring.
3. First letter 'a' -> "acbcbc" -> then answer be "ababab" -> because 'a' we skip and other letter we decrement. **c - 1 -> b** , **b - 1 -> a** ...etc.
4. Other cases


## Solution

1. We need start index which we will change symbols.
2. Then we iterate over string and change each symbols until 'a'
3. Return answer

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(n) - we using CharArray
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```kotlin []
class Solution {
    fun smallestString(s: String): String {
        if (s.hasSingle()) return when {
            s[0] == 'a' -> 'z'.toString()
            else -> Char(s[0].code - 1).toString()
        }
        val chars = s.toCharArray()
        val n = chars.size
        var start = -1

        for (i in 0 until n) {
            if (chars[i] != 'a') {
                start = i
                break
            }
        }

        if (start == -1) {
            chars[n - 1] = 'z'
            return String(chars)
        }

        for (i in start until n) {
            if (chars[i] != 'a') chars[i]--
            else break
        }

        return String(chars)
        
    }

    fun String.hasSingle(): Boolean = when {
        this.length == 1 -> true
        else -> false
    }
}
```
['Kotlin']