CareerCup The number of pairs (x, y) of distinct elements with condition x + y <= Threshold
2014-03-01 18:47
651 查看
Problem1: You have a lists with integers. Find all the pairs of numbers that sum less than or equal to to a particular number k. The
list contains minimum 5 Million number.
(I provided a n^2logn solution but they may be looking forward to having a better answer).
----------------------------------------------------------------------------------------
Problem2:
Input - array of integers size N, integer Threshold. Output - the number of pairs (x, y) of distinct elements with condition x + y <= Threshold. Is that possible to implement it with O(n) ?
---------------------------------------------------------------------------------------
list contains minimum 5 Million number.
(I provided a n^2logn solution but they may be looking forward to having a better answer).
----------------------------------------------------------------------------------------
Problem2:
Input - array of integers size N, integer Threshold. Output - the number of pairs (x, y) of distinct elements with condition x + y <= Threshold. Is that possible to implement it with O(n) ?
---------------------------------------------------------------------------------------
// perform radix sort - O(n). now the array is sorted Or quicksort, O(n) is difficult // now, remove duplicates if you wish. and now perform the following algorithm int i(0), j(n-1), ans(0); while (i < j) { if (a[i] + a[j] <= threshold ) { ans += (j-i); i++; } else { j--; } } return ans;
相关文章推荐
- CareerCup Fill the array with product of all numbers except the number in that cell
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- CareerCup Find the smallest range that includes at least one number from each of the k sorted lists.
- CareerCup Given an array of (unsorted) integers, arrange them such that a < b > c < d > e... etc.
- <Socket> <BEA-000402> <There are: 5 active sockets, but the maximum number of socket reader threads
- CareerCup Output the amount of all possible strings of length N that don't of have consecutive a,b,c
- The value of attribute "description" associated with an element type "target" must not contain the '<' character.
- CareerCup Given an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.
- Codeforces 27E Number With The Given Amount Of Divisors
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
- The base class includes the field '...', but its type (...) is not compatible with the type of control (...)
- Some 3D Graphics (rgl) for Classification with Splines and Logistic Regression (from The Elements of Statistical Learning)(转)
- Note on <C# 3.0 UNLEASHED With the .NET Framework 3.5> - 02
- CF-27E - Number With The Given Amount Of Divisors(枚举+dfs)
- DEEP LEARNING IS THE FUTURE: Q&A WITH NAVEEN RAO OF NERVANA SYSTEMS
- The Nature of TaskCompletionSource<TResult>
- codeforces 27E - Number With The Given Amount Of Divisors (数论 dfs)
- P15 (**) Replicate the elements of a list a given number of times.
- [LeetCode] Next Permutation - Next bigger number with the same set of digits
- Initalizing 'AppDelegate * __strong' with an expression of incompatible type ''id<UIApplicatioinDele