def minimumCost(price):
n = len(price)
price.append(0)
ans = float('inf')
last = {price[0]: 0}
for i in range(1, n):
v = price[i]
price[i] += price[i - 1]
if last.get(v) != None:
ans = min(ans, price[i] - price[last[v]] + v)
last[v] = i
return ans if ans != float('inf') else -1
n = int(input())
price = list(map(int,input().split(' ')))
print(minimumCost(price))
Python 3
Amazon
Telegram:- @allcoding1_official
n = len(price)
price.append(0)
ans = float('inf')
last = {price[0]: 0}
for i in range(1, n):
v = price[i]
price[i] += price[i - 1]
if last.get(v) != None:
ans = min(ans, price[i] - price[last[v]] + v)
last[v] = i
return ans if ans != float('inf') else -1
n = int(input())
price = list(map(int,input().split(' ')))
print(minimumCost(price))
Python 3
Amazon
Telegram:- @allcoding1_official
π11β€1
string getLongestRegex(string a, string b, string c)
{
const size_t n = a.size();
int idx = -1;
for (int i = 0; i < n; i++) {
if (c[i] != a[i] && c[i] != b[i]) { idx = i; }
}
if (idx == -1) return "-1";
string res;
for (int i = 0; i < n; i++) {
if (i == idx) {
string cur = "[";
for (int j = 'A'; j <= 'Z'; j++) if (j != c[i]) cur += j;
cur += "]";
res += cur;
} else {
res += "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]";
}
}
return res;
}
C++
Amazon
Telegram:- @allcoding1_official
{
const size_t n = a.size();
int idx = -1;
for (int i = 0; i < n; i++) {
if (c[i] != a[i] && c[i] != b[i]) { idx = i; }
}
if (idx == -1) return "-1";
string res;
for (int i = 0; i < n; i++) {
if (i == idx) {
string cur = "[";
for (int j = 'A'; j <= 'Z'; j++) if (j != c[i]) cur += j;
cur += "]";
res += cur;
} else {
res += "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]";
}
}
return res;
}
C++
Amazon
Telegram:- @allcoding1_official
π25β€4
π
ΎοΈFree off cost
πALL IT companies (materials, exams questions & Answers paper's)
πALL software courses with certification
π ΎοΈFree off cost
Join now π
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
β Please send with your friends and college groups
πALL IT companies (materials, exams questions & Answers paper's)
πALL software courses with certification
π ΎοΈFree off cost
Join now π
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
β Please send with your friends and college groups
π40β€5π5π1
Both conclusions I and II are not definitely true based on the information provided.
Tech Mahindra exam Ans
@allcoding1_official
Tech Mahindra exam Ans
@allcoding1_official
π2
Both statements put together are sufficient to answer the problem
Tech Mahindra exam Ans
@allcoding1_official
Tech Mahindra exam Ans
@allcoding1_official