LeetCode in Kotlin

3210. Find the Encrypted String

Easy

You are given a string s and an integer k. Encrypt the string using the following algorithm:

Return the encrypted string.

Example 1:

Input: s = “dart”, k = 3

Output: “tdar”

Explanation:

Example 2:

Input: s = “aaa”, k = 1

Output: “aaa”

Explanation:

As all the characters are the same, the encrypted string will also be the same.

Constraints:

Solution

@Suppress("NAME_SHADOWING")
class Solution {
    fun getEncryptedString(s: String, k: Int): String {
        var k = k
        val n = s.length
        k %= n
        val str = StringBuilder(s.substring(k, n))
        str.append(s.substring(0, k))
        return str.toString()
    }
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy