def countPalin(str):
count = 0
# splitting each word as spaces as
# delimiter and storing it into a list
listOfWords = str.split(" ")
# Iterating every element from list
# and checking if it is a palindrome.
for elements in listOfWords:
if (checkPalin(elements)):
# if the word is a palindrome
# increment the count.
count += 1
print (count)
# Driver code
countPalin("Madam Arora teaches malayalam")
countPalin("Nitin speaks malayalam")
Python
Palindrome count
Telegram - https://t.me/Coding_human
count = 0
# splitting each word as spaces as
# delimiter and storing it into a list
listOfWords = str.split(" ")
# Iterating every element from list
# and checking if it is a palindrome.
for elements in listOfWords:
if (checkPalin(elements)):
# if the word is a palindrome
# increment the count.
count += 1
print (count)
# Driver code
countPalin("Madam Arora teaches malayalam")
countPalin("Nitin speaks malayalam")
Python
Palindrome count
Telegram - https://t.me/Coding_human
n=input()
m=input()
if m in n:
print("yes")
else:
print("No")
Python
String within String Code
Telegram https://t.me/Coding_human
m=input()
if m in n:
print("yes")
else:
print("No")
Python
String within String Code
Telegram https://t.me/Coding_human
n = int(input())
A = int(input())
A1 = []
A2= []
A3= []
ans = 0
https://t.me/Coding_human
for i in range(n):
A1.append(int(input()))
for j in range(n):
A2.append(int(input()))
for k in range(n):
A2.append([p[k], b[k]])
a.sort()
for z in a:
if a[0] > N:
break
N += a[1]
ans += 1
print(ans)
Try this code for this question... Python 3
Telegram:-https://t.me/Coding_human
https://t.me/infosys_sp_dsp_all_code
A = int(input())
A1 = []
A2= []
A3= []
ans = 0
https://t.me/Coding_human
for i in range(n):
A1.append(int(input()))
for j in range(n):
A2.append(int(input()))
for k in range(n):
A2.append([p[k], b[k]])
a.sort()
for z in a:
if a[0] > N:
break
N += a[1]
ans += 1
print(ans)
Try this code for this question... Python 3
Telegram:-https://t.me/Coding_human
https://t.me/infosys_sp_dsp_all_code
Guys ❤️
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
C++
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Number Of Subsequences Code For Infosys
int A[] = {10,13,7,8,14,11};
int n = 6;
int memo[6];//initialized with -1s;
int count(int currIndex){
if (currIndex == n-1) return 1;
if (memo[currIndex] != -1) return memo[currIndex];
int res = 0;
for (int i=currIndex+1 ; i<n ; i++){
if (abss(A[currIndex] - A[i]) <= 3){
res += count(i);
}
}
memo[currIndex] = res;
return res;
}
c++
Telegram:- https://t.me/Coding_human
int A[] = {10,13,7,8,14,11};
int n = 6;
int memo[6];//initialized with -1s;
int count(int currIndex){
if (currIndex == n-1) return 1;
if (memo[currIndex] != -1) return memo[currIndex];
int res = 0;
for (int i=currIndex+1 ; i<n ; i++){
if (abss(A[currIndex] - A[i]) <= 3){
res += count(i);
}
}
memo[currIndex] = res;
return res;
}
c++
Telegram:- https://t.me/Coding_human
Guys ❤️
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
// Infosys
// N flowers on a Recatangular pana
int ans = 100000000;
void solve(vector<int> a, int n, int k, int index, int sum,
int maxsum)
{
if (k == 1)
{
maxsum = max(maxsum, sum);
sum = 0;
for (int i = index; i < n; i++)
{
sum += a[i];
}
maxsum = max(maxsum, sum);
ans = min(ans, maxsum);
return;
}
sum = 0;
for (int i = index; i < n; i++)
{
sum += a[i];
maxsum = max(maxsum, sum);
solve(a, n, k - 1, i + 1, sum, maxsum);
}
}
int GetMaxBeauty(int N, int K, vector<int> A)
{
solve(A, N, K, 0, 0, 0);
return ans;
}
Telegram:- https://t.me/Coding_human
// N flowers on a Recatangular pana
int ans = 100000000;
void solve(vector<int> a, int n, int k, int index, int sum,
int maxsum)
{
if (k == 1)
{
maxsum = max(maxsum, sum);
sum = 0;
for (int i = index; i < n; i++)
{
sum += a[i];
}
maxsum = max(maxsum, sum);
ans = min(ans, maxsum);
return;
}
sum = 0;
for (int i = index; i < n; i++)
{
sum += a[i];
maxsum = max(maxsum, sum);
solve(a, n, k - 1, i + 1, sum, maxsum);
}
}
int GetMaxBeauty(int N, int K, vector<int> A)
{
solve(A, N, K, 0, 0, 0);
return ans;
}
Telegram:- https://t.me/Coding_human
class CountOccurrences {
public static void main(String[] args) {
String str = "aabbccd";
char a[]=str.toCharArray();
int cnt = 0;
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++)
{
if ((a[i] == a[j])) {
cnt++;
}
}
}
System.out.println(cnt);
}
}
Java
Telegram:-https://t.me/Coding_human
public static void main(String[] args) {
String str = "aabbccd";
char a[]=str.toCharArray();
int cnt = 0;
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++)
{
if ((a[i] == a[j])) {
cnt++;
}
}
}
System.out.println(cnt);
}
}
Java
Telegram:-https://t.me/Coding_human
Guys ❤️
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Infosys Exam on 29/7/22 , 30/7/22,31/07/22
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Guys ❤️
Infosys Exam 3 PM Solution
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Infosys Exam 3 PM Solution
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
def minOperations(arr1, arr2, i, j):
# Base Case
if arr1 == arr2:
return 0
if i >= len(arr1) or j >= len(arr2):
return 0
# If arr[i] < arr[j]
if arr1[i] < arr2[j]:
# Include the current element
return 1 \
+ minOperations(arr1, arr2, i + 1, j + 1)
# Otherwise, excluding the current element
return max(minOperations(arr1, arr2, i, j + 1),
minOperations(arr1, arr2, i + 1, j))
# Function that counts the minimum
# moves required to sort the array
def minOperationsUtil(arr):
https://t.me/Coding_human
brr = sorted(arr);
# If both the arrays are equal
if(arr == brr):
# No moves required
print("0")
# Otherwise
else:
# Print minimum operations required
print(minOperations(arr, brr,)
Python
Q) minimum operations
Telegram - https://t.me/Coding_human
# Base Case
if arr1 == arr2:
return 0
if i >= len(arr1) or j >= len(arr2):
return 0
# If arr[i] < arr[j]
if arr1[i] < arr2[j]:
# Include the current element
return 1 \
+ minOperations(arr1, arr2, i + 1, j + 1)
# Otherwise, excluding the current element
return max(minOperations(arr1, arr2, i, j + 1),
minOperations(arr1, arr2, i + 1, j))
# Function that counts the minimum
# moves required to sort the array
def minOperationsUtil(arr):
https://t.me/Coding_human
brr = sorted(arr);
# If both the arrays are equal
if(arr == brr):
# No moves required
print("0")
# Otherwise
else:
# Print minimum operations required
print(minOperations(arr, brr,)
Python
Q) minimum operations
Telegram - https://t.me/Coding_human
array AR of size N
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
// https://t.me/Coding_human
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
Python
Telegram:-https://t.me/Coding_human
perfect_sum(arr, s, result) :
x = [0]*len(arr)
j = len(arr) - 1
while (s > 0) :
x[j] = s % 2
s = s // 2
j -= 1
sum = 0
// https://t.me/Coding_human
for i in range(len(arr)) :
if (x[i] == 1) :
sum += arr[i]
if (sum == result) :
print("{",end="");
for i in range(len(arr)) :
if (x[i] == 1) :
print(arr[i],end= ", ");
print("}, ",end="")
def print_subset(arr, K) :
x = pow(2, len(arr))
for i in range(1, x):
perfect_sum(arr, i, K)
# Driver code
arr = [ ]
n = int(input("Enter length of array : "))
s=int(input("Enter sum : "))
for i in range(n):
ele=int(input("Enter element : "))
arr.append(ele)
print_subset(arr, s)
Python
Telegram:-https://t.me/Coding_human
# A Naive recursive python program to find minimum of coins
# to make a given change V
import sys
# m is size of coins array (number of different coins)
def minCoins(coins, m, V):
# base case
if (V == 0):
return 0
# Initialize result
res = sys.maxsize
# Try every coin that has smaller value than V
for i in range(0, m):
if (coins[i] <= V):
sub_res = minCoins(coins, m, V-coins[i])
# Check for INT_MAX to avoid overflow and see if
# result can minimized
if (sub_res != sys.maxsize and sub_res + 1 < res):
res = sub_res + 1
// https://t.me/Coding_human
return res
# Driver program to test above function
coins = [9, 6, 5, 1]
m = len(coins)
V = 11
print("Minimum coins required is",minCoins(coins, m, V))
Python 3
Telegram:- https://t.me/Coding_human
# to make a given change V
import sys
# m is size of coins array (number of different coins)
def minCoins(coins, m, V):
# base case
if (V == 0):
return 0
# Initialize result
res = sys.maxsize
# Try every coin that has smaller value than V
for i in range(0, m):
if (coins[i] <= V):
sub_res = minCoins(coins, m, V-coins[i])
# Check for INT_MAX to avoid overflow and see if
# result can minimized
if (sub_res != sys.maxsize and sub_res + 1 < res):
res = sub_res + 1
// https://t.me/Coding_human
return res
# Driver program to test above function
coins = [9, 6, 5, 1]
m = len(coins)
V = 11
print("Minimum coins required is",minCoins(coins, m, V))
Python 3
Telegram:- https://t.me/Coding_human
Guys ❤️
Infosys Exam 3 PM Solution
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.
Infosys Exam 3 PM Solution
Telegram:- https://t.me/infosys_sp_dsp_all_code
https://t.me/Coding_human
Note : Some codes are already in the channel/group, you can search the code by their names.