1625. Lexicographically Smallest String After Applying Operations
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class Solution {
    public String findLexSmallestString(String s, int a, int b) {
        String res = s;
        Set<String> seen = new HashSet<>();
        Queue<String> queue = new LinkedList<>();
        queue.offer(s);
        seen.add(s);

        while (!queue.isEmpty()) {
            String current = queue.poll();
            res = minString(res, current);

            // Apply operation 1: Rotate string by b positions
            String rotated = rotate(current, b);
            if (!seen.contains(rotated)) {
                queue.offer(rotated);
                seen.add(rotated);
            }

            // Apply operation 2: Add 'a' to odd indices
            String added = addAll(current, a);
            if (!seen.contains(added)) {
                queue.offer(added);
                seen.add(added);
            }
        }

        return res;
    }

    // Rotate the string by 'b' positions
    private String rotate(String s, int b) {
        int n = s.length();
        b = b % n;  // No need to rotate more than the length of the string
        return s.substring(n - b) + s.substring(0, n - b);
    }

    // Add 'a' to all odd indices
    private String addAll(String s, int a) {
        char[] chars = s.toCharArray();
        for (int i = 1; i < s.length(); i += 2) {
            int val = (chars[i] - '0' + a) % 10;
            chars[i] = (char) ('0' + val);
        }
        return new String(chars);
    }

    // Compare and return the lexicographically smallest string
    private String minString(String s1, String s2) {
        return s1.compareTo(s2) < 0 ? s1 : s2;
    }
}

```
['Java']