Search
 
SCRIPT & CODE EXAMPLE
 

CPP

two elements with difference K in c++

bool diffK(int A[], int N, int K) {
    sort(A, A+N);
    int i = 0, j = 0;
    while (i < N && j < N) {
        if (A[i] == A[j] + K) return true;
        else if (A[i] < A[j] + K) i++;
        else j++;
    }
    return false;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: rotate an array of n elements to the right by k steps 
Cpp :: Youtube backlink generator tool 
Cpp :: visual studio getline not working 
Cpp :: double array size c++ 
Cpp :: class operator overloading c++ 
Cpp :: c++ inheritance 
Cpp :: sum array c++ 
Cpp :: what do you mean by smallest anagram of a string 
Cpp :: why do we use pointers in c++ 
Cpp :: stl in c++ 
Cpp :: how to sort array in c++ 
Cpp :: c++ template vs code 
Cpp :: ue4 c++ replicate actor variable 
Cpp :: clear previous terminal output c++ 
Cpp :: glm has no member value_ptr 
Cpp :: c++ multiply char 
Cpp :: c++ map lookup 
Cpp :: C++ cout iostream 
Cpp :: how to pass an array by reference in c++ 
Cpp :: how to get last element of set 
Cpp :: c++ catch Unhandled exception 
Cpp :: Converting Strings to Numbers in C/C++ 
Cpp :: runtime 
Cpp :: dangling pointer 
Cpp :: valid parentheses in c++ 
Cpp :: cpp language explained 
Cpp :: error in c++ 
Cpp :: c++ map vector as keys 
Cpp :: why exceptions can lead to memory leaks 
Cpp :: c++ *agrs 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =