Advance Coding4
Advance Coding4
VU21CSEN0100455
ADVANCE CODING-4
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:
Output: 3
Example 2:
Output: 10
Example 3:
Output: -2
Constraints:
• n == nums.length
CODE:
class Solution {
int totalSum = 0;
for(int i=0;i<A.length;i++){
totalSum += A[i];
A[i] = -A[i];
if(circularSum == 0)
return nonCircularSum;
return Math.max(circularSum,nonCircularSum);
for(int i=1;i<A.length;i++){
if(currentSum < 0)
currentSum = 0;
maxSum = Math.max(maxSum,currentSum);
return maxSum;
SUBMISSION RESULT:
SUDHIT JALAY
VU21CSEN0100455
TEST CASE 1
SUDHIT JALAY
VU21CSEN0100455
TEST CASE2
TEST CASE 3
SUDHIT JALAY
VU21CSEN0100455
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:
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).
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:
Output: [0,2]
Example 2:
Output: [3,0,1]
Constraints:
CODE
class Solution {
char[] S = stamp.toCharArray();
char[] T = target.toCharArray();
int stars = 0;
doneReplace = true;
visited[i] = true;
res.add(i);
if (stars == T.length) {
SUDHIT JALAY
VU21CSEN0100455
break;
if (!doneReplace) {
return resArray;
return false;
return true;
if (T[i + p] != '*') {
T[i + p] = '*';
count++;
SUDHIT JALAY
VU21CSEN0100455
return count;
SUBMISSION RESULT
SUDHIT JALAY
VU21CSEN0100455
TEST CASE1
TESTCASE2
SUDHIT JALAY
VU21CSEN0100455