def isMonotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1))) # main A = [5,6,7,8,9,10,11,12] print(isMonotonic(A)) def isMonotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in... Continue Reading →
Finding the remainder of array multiplication divided n
#include <iostream> using namespace std; int findrem(int arr[], int len, int n) { int mul = 1; for (int i = 0; i < len; i++) mul = (mul * (arr[i] % n)) % n; return mul % n; } int main() { int arr[] = { 10, 18, 45, 7, 12, 20 }; int... Continue Reading →
Splitting the array and adding the first part at the end
#include <bits/stdc++.h> using namespace std; void splitArr(int arr[], int n, int k) { for (int i = 0; i < k; i++) { int x = arr[0]; for (int j = 0; j < n - 1; ++j) arr[j] = arr[j + 1]; arr[n - 1] = x; } } int main() { int arr[]... Continue Reading →
Sum of elements of array
#include <iostream> using namespace std; int main (){ int arr[] = {6,12,4,7,9 }; int n = 7, sum = 0; for(int i = 0; i<n ; i++){ sum+=arr[i]; } cout<<"The array sum is "<<sum; return 0; }