Skip to main content

Command Palette

Search for a command to run...

Find the Encrypted String

Published
1 min read
Find the Encrypted String
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

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

  • For each character c in s, replace c with the k<sup>th</sup> character after c in the string (in a cyclic manner).

Return the encrypted string.

LeetCode Problem - 3210

class Solution {
    public String getEncryptedString(String s, int k) {
        // Initialize a StringBuilder to build the encrypted string
        StringBuilder sb = new StringBuilder();
        // Get the length of the input string
        int n = s.length();

        // Iterate through each character of the input string
        for (int i = 0; i < n; i++) {
            // Append the character at the new position (i + k) % n to the StringBuilder
            sb.append(s.charAt((i + k) % n));
        }

        // Convert the StringBuilder to a string and return it
        return sb.toString();
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.