👍1
CᴏᴅɪɴɢNᴇʀᴅ 💸🐾
Question 5 : Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1, 2, 3, 1] Output: true Example 2: Input: nums = [1, 2, 3, 4] Output: false…
#include <stdio.h>
int check_dual_int(int arr[], int length) {
for (int i = 0; i < length; i++) {
for(int j=i+1; j< length; j++) {
if(arr[i] == arr[j]) {
return 1;
}
}
}
return 0;
}
int main() {
int arr[] = {1, 2, 3, 1};
int length = sizeof(arr) / sizeof(arr[0]);
if(check_dual_int(arr, length) == 1) {
printf("True");
} else {
printf("False");
};
return 0;
}
🔥2👾2👍1
Day 05 👾:
Given an arrayarr[]
of size n, the task is to print the lexicographically next greater permutation of the given array. If there does not exist any greater permutation, then find the lexicographically smallest permutation of the given array.
Let us understand the problem better by writing all permutations of[1, 2, 4]
in lexicographical order[1, 2, 4], [1, 4, 2], [2, 1, 4], [2, 4, 1], [4, 1, 2] and [4, 2, 1]
If we give any of the above (except the last) as input, we need to find the next one in sequence. If we give last as input, we need to return the first one.
🔥2👨💻2❤1