Advance Coding4
Advance Coding4
KARTHIKEYA
VU21CSEN0101813
ADVANCE CODING-4
N.KARTHIKEYA
VU21CSEN0101813
QUESTION1
Given a circular integer array nums of length n, return the maximum possible
sum of a non-empty subarray of nums.
A circular array means the end of the array connects to the beginning of the
array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the
previous element of nums[i] is nums[(i - 1 + n) % n].
A subarray may only include each element of the fixed buffer nums at most
once. Formally, for a subarray nums[i], nums[i + 1], ..., nums[j], there does not
exist i <= k1, k2 <= j with k1 % n == k2 % n.
Example 1:
Input: nums = [1,-2,3,-2]
Output: 3
Explanation: Subarray [3] has maximum sum 3.
Example 2:
Input: nums = [5,-3,5]
Output: 10
Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.
Example 3:
Input: nums = [-3,-2,-3]
Output: -2
Explanation: Subarray [-2] has maximum sum -2.
Constraints:
n == nums.length
1 <= n <= 3 * 104
-3 * 104 <= nums[i] <= 3 * 104
CODE:
class Solution {
N.KARTHIKEYA
VU21CSEN0101813
TEST CASE 1
N.KARTHIKEYA
VU21CSEN0101813
TEST CASE2
TEST CASE 3
N.KARTHIKEYA
VU21CSEN0101813
QUESTION2
You are given two strings stamp and target. Initially, there is a string s of
length target.length with all s[i] == '?'.
In one turn, you can place stamp over s and replace every letter in the s with the
corresponding letter from stamp.
For example, if stamp = "abc" and target = "abcba",
then s is "?????" initially. In one turn you can:
place stamp at index 0 of s to obtain "abc??",
place stamp at index 1 of s to obtain "?abc?", or
place stamp at index 2 of s to obtain "??abc".
Note that stamp must be fully contained in the boundaries of s in order to stamp
(i.e., you cannot place stamp at index 3 of s).
We want to convert s to target using at most 10 * target.length turns.
Return an array of the index of the left-most letter being stamped at each turn. If
we cannot obtain target from s within 10 * target.length turns, return an empty
array.
Example 1:
Input: stamp = "abc", target = "ababc"
Output: [0,2]
Explanation: Initially s = "?????".
- Place stamp at index 0 to get "abc??".
N.KARTHIKEYA
VU21CSEN0101813
Constraints:
1 <= stamp.length <= target.length <= 1000
stamp and target consist of lowercase English letters.
CODE
class Solution {
public int[] movesToStamp(String stamp, String target) {
char[] S = stamp.toCharArray();
char[] T = target.toCharArray();
List<Integer> res = new ArrayList<>();
boolean[] visited = new boolean[T.length];
int stars = 0;
}
}
}
if (!doneReplace) {
return new int[0];
}
}
return count;
}
}
SUBMISSION RESULT
TEST CASE1
N.KARTHIKEYA
VU21CSEN0101813
TESTCASE2
N.KARTHIKEYA
VU21CSEN0101813