String Transformation (Also for Infra Automation Intern)
See Snowflake hiring insights
The NLP enthusiasts of Hackerland are working on a string transformation algorithm. In a single operation, a string s can be transformed into another string by removing a suffix of the string and adding the removed suffix in front of the remaining string. For example, the string "abcd" can be transformed to "dabc" by removing the suffix "d" and adding it to the front of the remaining string "abc".
Given two strings src and target of lowercase English characters and an integer k, find the number of ways to transform the string src to the string target using the given algorithm in exactly k steps. Since the answer can be large, report it modulo 10^9 + 7.
Note: Two ways are considered different if the sequence of indices chosen for breaking the suffix is different at 1 or more steps.
Complete the function getNumWays in the editor.
getNumWays has the following parameter(s):
- 1.
string src: the source string - 2.
string target: the target string - 3.
int k: the number of steps
Returns
int: the number of ways modulo 10^9 + 7
src = "ababab" target = "ababab" k = 1 return = 2
src to target in a single operation.src = "aaaa" target = "aaaa" k = 2 return = 9
src to the target.src = "aaaa" target = "aaaa" k = 2 return = 9
src to the target.- 2 ≤ length(src) ≤ 1000
- 2 ≤ length(target) ≤ 1000
- 1 ≤ k ≤ 10^6
- Effective Role PrivilegesPHONE SCREEN · Seen May 2026
- Closest Bathroom / Desk on a GridPHONE SCREEN · Seen May 2026
- Minimum Clicks Between Wiki PagesOA · Seen May 2026
- Minimum Index Distance Between Person and CakeOA · Seen May 2026
- Simple Array Rotation GameSeen Apr 2026
- Max Element Indexes After RotationsOA · Seen Mar 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Mar 2026
- Grid Traversal (Infrastructure Automation Internship)Seen May 2025
public int getNumWays(String src, String target, int k) {
// write your code here
}