@Hemesh : +1
@Jalaj : read Hemesh's solution again it is for 4sum.
In short, make a new array having sum of each unique pair of given array.
- O(n^2)
sort it - O(n^2)
for each number bi in new array, binary search (target - bi) in the same
array - O(n^2)
On Sunday, 17 June 2012 12:41:40
Hi,
I am trying to solve this problem.
http://www.spoj.pl/problems/SCUBADIV/
But I am getting a lot of WAs!
Any good logic(Solution) to solve the problem?
Thanks in advance for your reply.
Rituraj
2nd year
B.Tech(CSE)
NIT-Patna
--
You received this message because you are subscribed to
Thanks Hassan. But I was more interested in knowing the mathematic proof of
Partial Quick Sort.
--
Amitesh
On Sun, Jun 17, 2012 at 7:54 PM, Hassan Monfared hmonfa...@gmail.comwrote:
O(N*logM)
On Sat, Jun 16, 2012 at 5:15 PM, Amitesh Singh singh.amit...@gmail.comwrote:
Hi Guys,
http://www.spoj.pl/problems/FAVDICE/
On Sun, Jun 17, 2012 at 8:43 PM, Doom duman...@gmail.com wrote:
If we expand it.. E(t) = E(t1) + E(t2) + E(t3) + ... + E(tn);
here I am able to derive E(t1) as N/1 using the expression E(t1) = 1/N +
((N-1)/N)(E(t1) + 1);
but how do I proceed?
How do I
We can also build a Balanced BST for the window elements and on each shift
we need to have a delete operation and add oeration.
O(n logk)
Also we can add the Shashank algo
where we check if the newly added element is greater than the current BST's
max element.
So we can discard the current BSt
We can use Median of medians
http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm
On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote:
Give an array of unsorted elements, find the kth smallest element in the
array.
This is typical knapsack problem.
On Mon, Jun 18, 2012 at 10:33 AM, Rituraj worstcod...@gmail.com wrote:
Hi,
I am trying to solve this problem.
http://www.spoj.pl/problems/SCUBADIV/
But I am getting a lot of WA!
Any good logic(solution) to solve the problem?
Thanks in advance for your
Hi all,
A variation of selection sort can be used which takes O(nk) time.
for i 1 to k
min_index = i
for j i+1 to n
if a[j] a[min_index]
min_index = j
swap(a[i],a[min_index])
required element : a[k]
On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote:
Give
@hemesh,kk:
let's take a test case :
arr: 2 4 6 8
arr^2 : 6 8 10 10 12 14(sum of each unique pair in arr[i])
let's say target sum is 26
your solution will return true as they 12+14=26 but in 12 and 14, 8 is
common, infact 26 is not possible in the given array
can u
here is my code:
#includestdio.h
#includestring.h
#includestdlib.h
int main()
{
int t,i,j,k1,k2,ans[40],sum,sum1;
char str[40][20],str1[6],str2[6];
scanf(%d,t);
for(i=0;i=t;i++)
{
gets(str[i]);
}
for(i=1;i=t;i++)
{
for(j=1,k1=0;j15,k15;j=j+3,k1++)
it also ran successfully on ideone.com
plz help me
i am classifying the card in two parts:
one with same suit
and other with different suit...
plz let me know if futher explanation is needed abt the code
help me regarding this..
thanx
--
You received this message because you are subscribed
Let us see what we have - we basically have an expression A || B C.
We also know the following:
1. || and are both considered sequence points
2. The has precedence over the || operator
3. The C/C++ languages use minimal evaluation principle when evaluating the
logical expressions (see the
Your code fails on one of the test cases like 5H 6H 7H 8H 9H.
it should give straight flush instead of flush, Think of all such
cases are change accordingly ..
On Mon, Jun 18, 2012 at 10:01 PM, Mayank Singh
singh13490may...@gmail.com wrote:
it also ran successfully on ideone.com
plz help me
i
@hemesh :- please explain your approach
On Mon, Jun 18, 2012 at 2:58 PM, Amol Sharma amolsharm...@gmail.com wrote:
@hemesh,kk:
let's take a test case :
arr: 2 4 6 8
arr^2 : 6 8 10 10 12 14(sum of each unique pair in arr[i])
let's say target sum is 26
your
In a stack, you can't access any element directly, except the top one.
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote:
My iterative approach
/*code in c*/
#includestdio.h
int main()
{
int stack[]={1,2,3,4,5,6,7,8},top=7;//
int i,j,temp;
for(i=1;i=top;i++)
{
this is not a stack at all, u have just named it as a stack. for it to be a
stack u should access only the top most element at any point of time!!!
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote:
My iterative approach
/*code in c*/
#includestdio.h
int main()
{
int
I think there is a problem in this solution.
U r accessing stack elements from 1 to n in the outer loop. It is not
possible. 1st element cannot be accessed without popping first n-1 elements
out.
On Mon, Jun 18, 2012 at 11:33 AM, Rituraj worstcod...@gmail.com wrote:
My iterative approach
@enchantress : This problem can be solved using quicksort in O(nlogn). No
need to go for selection sort.
But O(n) solution is needed.
On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.com wrote:
Hi all,
A variation of selection sort can be used which takes O(nk) time.
for i 1
I found it in some paper ;)
Diameter and center
De nition 4. The diameter of tree is the length of the longest path.
De nition 5. A center is a vertex v such that the longest path from v to a
leaf is minimal
over all vertices in the tree.Tree center(s) can be found using simple
algorithm.
19 matches
Mail list logo