B is brute force
Check for every factor of n
calculate max min for each one and find the max difference between them
Check for every factor of n
calculate max min for each one and find the max difference between them
๐11โค5๐1
D is also easy, just count the frequency of each element
Then add fC2 for every frequency
and there is special case that 2^4 = 4^2 so just add the product of freq of 2 and freq of 4 ๐โค๏ธ
Then add fC2 for every frequency
and there is special case that 2^4 = 4^2 so just add the product of freq of 2 and freq of 4 ๐โค๏ธ
E solution
Find the smallest element index and if the array is sorted from there then print its index otherwise if not sorted print -1
Find the smallest element index and if the array is sorted from there then print its index otherwise if not sorted print -1
void code()
{
int n;
cin >> n;
vector<int> arr(n);
for (int &i : arr)
cin >> i;
int minIndex = 0;
for (int i = 0; i < n; i++)
if (arr[i] < arr[minIndex])
minIndex = i;
int res = minIndex;
for (int i = minIndex; i < n - 1; i++)
if (arr[i] > arr[i + 1])
res = -1;
cout << res << endl;
}
// E
// Enjoy โค๏ธ
{
int n;
cin >> n;
vector<int> arr(n);
for (int &i : arr)
cin >> i;
int minIndex = 0;
for (int i = 0; i < n; i++)
if (arr[i] < arr[minIndex])
minIndex = i;
int res = minIndex;
for (int i = minIndex; i < n - 1; i++)
if (arr[i] > arr[i + 1])
res = -1;
cout << res << endl;
}
// E
// Enjoy โค๏ธ
โค11๐4๐1
Anyone wants to buy 4 โญ๏ธ codechef id, dm me ๐ซ
@cp_wala
@cp_wala
Anyone wants to buy Leetcode Guardian ID dm me ๐
@cp_Wala
@cp_Wala
๐2๐ฅ1
Channel name was changed to ยซCodeforces and Codechef Solutionsยป
anyone wants 4 star codechef id in minimum price, dm me @cp_wala