two elements with difference K in c++
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;
}
Also in C++:
- Title
- dfenwick tree code c++
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- c++ passing two dimensional array to function
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- c++ base 10 to base 2
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- c++ clamp
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- calling a method on an object c++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- how to print 5 precision float in c++
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- how to return a vector c++
- Category
- C++
- Title
- #include
- Category
- C++
- Title
- find all occurrences of a substring in a string c++
- Category
- C++
- Title
- c++ evaluate expression
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- how to get size of 2d vector in c++
- Category
- C++
- Title
- how to get the largest number in a c++ array
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- string to upper c++
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- correct sequence of compilation process in c++
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- how to swap string characters in c++
- Category
- C++
- Title
- c++ how to make a negative float positive
- Category
- C++
- Title
- cheap hosting
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- widechartomultibyte
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- sfml basic program
- Category
- C++
- Title
- coronavirus
- Category
- C++
- Title
- if not defined c++
- Category
- C++
- Title
- minmax_element c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- inverser les éléments d'un tableau manuellement en c++
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- insertion c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- how to write an or in c++
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- expected unqualified-id before 'if'
- Category
- C++
- Title
- matrix multiplication c++ eigen
- Category
- C++
- Title
- how to make a heap using stl in c++
- Category
- C++
- Title
- what is difference between single inverted and double inverted in programming languages
- Category
- C++
- Title
- equal elements in two arrays in c++
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- apple and orange hackerrank solution in c++
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- array as parameter c++
- Category
- C++
- Title
- file reading c++
- Category
- C++
- Title
- intersection between vector c++
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- what is sigsegv error in c++
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- c++ class method example
- Category
- C++
- Title
- c++ remove text file
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- c++ raw string
- Category
- C++
- Title
- std::substring
- Category
- C++