Re: [algogeeks] Re: Amazon Job openings

2021-07-16 Thread Rahul Vatsa
It's great to see this group active after such a long time, though it was not for discussing an algo, but I think it's fine if a member in the group needs some help in his/her professional career and asks for the same here. Many members in this group are in this industry from more than a decade or

Re: [algogeeks] Re: Amazon Job openings

2021-07-16 Thread Artemij Art
Hello, guys! Have a nice day. Greetings from Russia. пт, 16 июл. 2021 г., 09:19 Himanshu Singh : > Hello Guys, > > Sorry to say pls stop spamming whole group. > > Thanks. > > > On Fri, Jul 16, 2021, 11:46 AM Yash Khandelwal < > khandelwalyash...@gmail.com> wrote: > >> Done kindly check the mail >

Re: [algogeeks] Re: Amazon Job openings

2021-07-15 Thread Himanshu Singh
Hello Guys, Sorry to say pls stop spamming whole group. Thanks. On Fri, Jul 16, 2021, 11:46 AM Yash Khandelwal wrote: > Done kindly check the mail > > On Fri, Jul 16, 2021, 11:41 AM immanuel kingston < > kingston.imman...@gmail.com> wrote: > >> Please send a note to me on king...@amazon.com >

Re: [algogeeks] Re: Amazon Job openings

2021-07-15 Thread Yash Khandelwal
Done kindly check the mail On Fri, Jul 16, 2021, 11:41 AM immanuel kingston < kingston.imman...@gmail.com> wrote: > Please send a note to me on king...@amazon.com > > Thanks, > Kingston > > On Fri, Jul 16, 2021 at 11:16 AM immanuel kingston < > kingston.imman...@gmail.com> wrote: > >> Hi all, >>

[algogeeks] Re: Amazon Job openings

2021-07-15 Thread immanuel kingston
Please send a note to me on king...@amazon.com Thanks, Kingston On Fri, Jul 16, 2021 at 11:16 AM immanuel kingston < kingston.imman...@gmail.com> wrote: > Hi all, > > I am a hiring manager at Amazon. We are hiring for SDE and Applied Science > roles in my team. Please send a short note about you

Re: [algogeeks] Re: MICROSOFT:Given a BST and a number. Find two node in a BST whose sum is equal to given number in O(n) time and O(1) space.

2017-09-06 Thread Ganesh P Kumar
The O(1) space constraint is impossible, for any traversal will take Omega(n) stack space in the worst case. On Sep 5, 2017 10:38 PM, "deepikaanand" wrote: > using iterators: > > > __author__ = 'deepika' > > """ > This code will return iterator for inorder traversal of a BST > """ > class TreeNo

[algogeeks] Re: MICROSOFT:Given a BST and a number. Find two node in a BST whose sum is equal to given number in O(n) time and O(1) space.

2017-09-05 Thread deepikaanand
using iterators: __author__ = 'deepika' """ This code will return iterator for inorder traversal of a BST """ class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None def __repr__(self): return str(self.val)

Re: [algogeeks] Re: 25march

2016-06-07 Thread Tarun Sharma
Check here http://www.writeulearn.com/defective-ball-puzzle/ On Mon, Mar 28, 2011 at 5:54 PM, Subhransu wrote: > Worst Case scenario you will get in 3 steps > > 9 balls > > Compare 1st:123| 456| 789 > if (first > second) > //The ball is in 1st > Se

[algogeeks] Re: Minimal number of swaps

2016-04-23 Thread Dave
Use the quicksort algorithm: Set the swap counter to 0. Search from the beginning of the array for the first 0, and from the end of the array for the first 1. If the pointers cross, you are done; otherwise increment the swap counter and continue the searches. On Tuesday, March 29, 2016 at 9:00:

[algogeeks] Re: Minimal number of swaps

2016-04-22 Thread icy`
oh, nevermind, sorry ;P you want the 1's at the beginning, not the end... //friday On Friday, April 22, 2016 at 4:07:53 PM UTC-4, icy` wrote: > > Hi, > I'm not sure I understand the second example. Shouldn't the second one > also produce an answer of 1 (swap the one in index 1 with the zero

[algogeeks] Re: Minimal number of swaps

2016-04-22 Thread icy`
Hi, I'm not sure I understand the second example. Shouldn't the second one also produce an answer of 1 (swap the one in index 1 with the zero in the last index) 0 *1* 0 1 1 1 *0* icy` On Tuesday, March 29, 2016 at 10:00:21 AM UTC-4, Régis Bacra wrote: > > This puzzle comes from a contribution

[algogeeks] Re: Buying candy

2016-03-26 Thread Igor Pro
It is like bubble sort type of algorithm. I'm not tested it on different data sets, created just for fun and your critic) struct valuePos {int val; int pos;} valuePos[,] data = new valuePos[n,n]; // assign input data array to [val] properties // initialize by maximum val in data +1 or just unrea

[algogeeks] Re: Find all the subarrays in a given array with sum=k

2016-03-25 Thread Igor Pro
void findSum(int[] arr, int startPos, int finPos, int reqiredSum) // recursion procedure { int sum =0; // calculating sum of current(subarray) segment of array. imo single element is also a subarray so here we have i <= finPos in case when startPos == finPos for(int i = startPos, i

[algogeeks] Re: Largest Rectangle

2016-03-25 Thread Igor Pro
Use data structure to hold first position and last position of line // line - sequence of "0" elements in one of the dimensions in your matrix Search lines in each dimension and store in array of line[s] //for optimization, store in separate array for each dimension: array1stDimension,array2ndD

[algogeeks] Re: Find all the subarrays in a given array with sum=k

2016-03-11 Thread Ian Martin Ajzenszmidt
http://stackoverflow.com/questions/14948258/given-an-input-array-find-all-subarrays-with-given-sum-k On Sunday, 21 February 2016 20:48:42 UTC+11, Shubh Aggarwal wrote: > > Given an array of n elements(both +ve -ve allowed) > Find all the subarrays with a given sum k! > I know the solution using dy

[algogeeks] Re: Buying candy

2016-02-28 Thread Trevor
Don writes: > > JVC is a multi-part algorithm which consists of a shortest augmenting > path algorithm (JV) followed by a modified auction algorithm (C). It > is best implemented as a sparse matrix. JVC is definitely an example > of efficiency requiring a significant increase in complexity. The

Re: [algogeeks] Re: Find max sum of elements in an array ( with twist)

2016-01-12 Thread Saurabh Paliwal
you don't need to have arrays to store everything. A more memory efficient way is to store 2 values at each iteration whether to take this number or not. Below is a python code doing just that. def main(): numbers = map(int, raw_input().split()) maxTakingThis = 0 maxNotTaki

[algogeeks] Re: Find max sum of elements in an array ( with twist)

2016-01-12 Thread yomama
Here's a solution in javascript var data = [10 , 20 , 30, -10 , -50 , 40 , -50, -1, -3]; function max(array) { var i = array[0]; array.forEach(function(val) { if(val > i) i = val; }); return i; } function maxSum(i, data, canSkip) { var len = data.length -

[algogeeks] Re: Find max sum of elements in an array ( with twist)

2016-01-12 Thread yomama
Here's a solution in javascript var data = [10 , 20 , 30, -10 , -50 , 40 , -50, -1, -3]; function max(array) { var i = array[0]; array.forEach(function(val) { if(val > i) i = val; }); return i; } function maxSum(i, data, canSkip) { var len = data.length - i; if( len === 1)

[algogeeks] Re: Range Modulo Problem

2015-11-02 Thread Gideon Rosales
function solution( c1, c2, c3, c4 ) { var min; var max; var x; for( var y = c1; y <= c2; y++ ) { for( var z = c3; z <= c4; z++ ) { x = y % z; if ( !min ) { min = x;

Re: [algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread saurabh singh
Yes, I would like that. I am sure about other admins, but I am guilty of ignoring mails on the group. I am finding it hard to manage things between job, other interests and google groups that I own/moderate. People who want to volunteer to moderate this group, please reply (unicast to me, *avoid re

Re: [algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread Deshank Baranwal
I guess we need new admins who can actively moderate the group. On Mon, Nov 2, 2015 at 6:30 PM, Shachindra A C wrote: > Well, you need to ban a whole lot more people. > > On Mon, Nov 2, 2015 at 10:16 AM, saurabh singh > wrote: > >> FYI, have banned this user and several others who mistook this

Re: [algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread Shachindra A C
Well, you need to ban a whole lot more people. On Mon, Nov 2, 2015 at 10:16 AM, saurabh singh wrote: > FYI, have banned this user and several others who mistook this group for a > recruitment platform. Can we revive the legacy of this group again? > > > On Mon, Nov 2, 2015 at 11:36 PM Shaik Asif

[algogeeks] Re: [BANNED!!!] Urgent need Lead - Java Developer in Atlanta, GA

2015-11-02 Thread saurabh singh
FYI, have banned this user and several others who mistook this group for a recruitment platform. Can we revive the legacy of this group again? On Mon, Nov 2, 2015 at 11:36 PM Shaik Asif wrote: > Hi Partner, > > This is Shaik from Deegit Inc. Partner find the below requirement for your > consulta

[algogeeks] Re: Question on algo

2015-10-10 Thread Dave
Very simple. If MAXOR of the entire input set is not equal to zero, there are no subsets with equal MAXORs. If MAXOR of the entire set is zero, then any two complementary subsets have equal MAXORs. Since there are 2^N (^ is the exponential operator) subsets of a set of N elements, Little Panda

Re: [algogeeks] Re: Openings in Flipkart BLR

2015-10-05 Thread Shachindra A C
Sadly, this has become no more than a job portal without any discussions on algorithms at all... ~Sac On Sun, Oct 4, 2015 at 10:18 PM, taruna arora wrote: > Dear Sir, > > I am Taruna Arora working as Software Engineer with Indian Oil Corporation > Limited (PSU), Hire Date : 29th July, 2013. > >

[algogeeks] Re: Openings in Flipkart BLR

2015-10-04 Thread taruna arora
Dear Sir, I am Taruna Arora working as Software Engineer with Indian Oil Corporation Limited (PSU), Hire Date : 29th July, 2013. I came across your post today and wish to apply for the post of SDE1. Sir,I know its pretty late but I am enclosing my resume for further reference. Looking towards

[algogeeks] Re: Openings in Flipkart BLR

2015-10-04 Thread taruna arora
Dear Sir, I am Taruna Arora working as Software Engineer with Indian Oil Corporation Limited (PSU), Hire Date : 29th July, 2013. I came across your post today and wish to apply for the post of SDE1. Sir,I know its pretty late but I am enclosing my resume for further reference. Looking towards

Re: [algogeeks] Re: how to convert JSONObject object to java object ??

2015-06-19 Thread Ankit Agarwal
You can use Object Mapper, provided by com.fasterxml.jackson.core. There is a readValue which can convert string type object to any class object which you want. Check this maven repo for the jar Thanks & Regar

[algogeeks] Re: how to convert JSONObject object to java object ??

2015-06-18 Thread Nand Kumar Singh
Rest Url : http://localhost:8080//rest/hotel?{"location":"28.666045,77.185059","longitube":null,"latitude":null,"pincode":null,"childrens":0,"adults":1,"dateCheckIn":143468460,"dateCheckOut":143472420,"searchedString":"Sarai Rohilla Railway Station, Railway Officers Colony, New Delhi,

[algogeeks] Re: Openings in Snapdeal

2015-02-19 Thread NH
Thanks for the information . Can you also mention the job location ? On Wednesday, 18 February 2015 23:47:46 UTC-6, Romil... wrote: > > Hi everyone, > > Snapdeal is having a lot of open positions for developers both at senior > and junior level. > > Send your resumes to me at vamos...@gmail.c

[algogeeks] Re: Openings in Snapdeal

2015-02-19 Thread Romil Goyal
Forgot to mention: Applications only from tier 1 colleges will be preferred. On Thu, Feb 19, 2015 at 11:17 AM, Romil Goyal wrote: > Hi everyone, > > Snapdeal is having a lot of open positions for developers both at senior > and junior level. > > Send your resumes to me at vamosro...@gmail.com >

[algogeeks] Re: Opening in Microsoft India Development center, hyderabad.

2015-01-31 Thread ~*~VICKY~*~
Missed to add, preferably 1 year+ experience. On Sat, Jan 31, 2015 at 3:26 PM, ~*~VICKY~*~ wrote: > Hi folks, > > My team is expanding and looking for strong devs with deep understanding > of basics. If you think you can take up the challenge of redesigning and > optimizing the cloud computing w

[algogeeks] Re: Dynamic Programming - Series

2015-01-06 Thread aksam
what is square have -ve value then your solution gonna fail. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] Re: Comparing string of unequal length

2014-10-07 Thread Prateek Khandelwal
Below is my code where s1 is larger and s2 is smaller string paddedString(string s1, string s2){ int min = INT32_MAX, t, star = 0, diff = int(s1.size() - s2.size()); string result = ""; for (int i = 0; i <= diff; i++) { t = 0; for (int j = i; j < s2.size(); j++) { if (s1[

Re: [algogeeks] Re: Comparing string of unequal length

2014-10-07 Thread Rishav Mishra
Hi Vikas and Prateek, Vikas, the 'd' is arbitrary. The question is simply to return the padded string such that the number of similar characters in the padded smaller string (which is now equal in length to the bigger string) and the bigger string is the minimum. Prateek, I can understand the sol

Re: [algogeeks] Re: Comparing string of unequal length

2014-10-07 Thread Prateek Khandelwal
Just think in this manner that put 0 star in front, then 1 star in front and so on and while doing this just compare both the strings. If you are not able to understand just tell me I will mail my code to you. Prateek Khandelwal Software Engineer in Directi +91-7042393719 On Tue, Oct 7, 2014 at 1

Re: [algogeeks] Re: Comparing string of unequal length

2014-10-07 Thread Prateek Khandelwal
I think this question can be done in O((m-n)*n) where m is the length of larger string and n is the length of smaller string Prateek Khandelwal Software Engineer in Directi +91-7042393719 On Tue, Oct 7, 2014 at 6:06 PM, vikas wrote: > question unclear ?What is to be minimize ? > in given exampl

[algogeeks] Re: Comparing string of unequal length

2014-10-07 Thread vikas
question unclear ?What is to be minimize ? in given example: ca*d*bch abc what is role of "d" ? On Monday, 6 October 2014 22:52:10 UTC+5:30, Rishav wrote: > > Hi everyone, > > I was asked this question recently in an interview: Given two strings of > unequal length, you have to pad the smalle

[algogeeks] Re: Regarding approach to solve

2014-10-05 Thread Dave
Do a breadth-first search. From your starting position, find all of the positions you can reach in one move. From each of those, find all positions you can reach in one move. If you reach an already-reached position, just ignore that move; you either got to that position on an earlier move or vi

[algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread wtx...@gmail.com
Odysseus, What does char 'N' mean in chr22.dna? DNA has only 4 chars: A, C, G, T. Other DNA/RNA has any other chars? I read from wiki that 'U' appears in tRNA. Where is a tRNA file I can use? Thank you. Weng On Thursday, August 7, 2014 6:26:19 PM UTC-7, wtx...@gmail.com wrote: > > I am develo

[algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread wtx...@gmail.com
Odysseus, Thank you very much!!! I can open it with Microsoft' Notepad to view it. This is really what I want!!! Weng On Thursday, August 7, 2014 6:26:19 PM UTC-7, wtx...@gmail.com wrote: > > I am developing a new algorithm constructing Suffix Array that is not > based on KA, AS-IS or Skew

Re: [algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread Carl Barton
It's just a plain text file, use whatever text editor you like On 8 August 2014 10:42, wtx...@gmail.com wrote: > *I downloaded the file chr22.dna. I don't know what software should be > used to browse the contents and view its data pattern. This file is really > what I need to view its data pat

[algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread wtx...@gmail.com
*I downloaded the file chr22.dna. I don't know what software should be used to browse the contents and view its data pattern. This file is really what I need to view its data pattern.**Please help tell me what **software should be used to browse the contents.* *Weng* *Can't Open .DNA Files ?*Yo

Re: [algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread Carl Barton
Almost certainly yes, but that website also gives the links to the files used in the benchmark. So you can just check yourself. On 8 August 2014 10:23, wtx...@gmail.com wrote: > Here is Google Suffix array testing result website. > > https://sites.google.com/site/yuta256/sais > > I want to know

[algogeeks] Re: I am developing a new algorithm constructing Suffix Array and I want some knowledge on genome

2014-08-08 Thread wtx...@gmail.com
Here is Google Suffix array testing result website. https://sites.google.com/site/yuta256/sais I want to know if the testing corpus contains DNA bio information? It has a file named chr22.dna. Is it chromosome 22 DNA? Weng On Thursday, August 7, 2014 6:26:19 PM UTC-7, wtx...@gmail.com wrote:

[algogeeks] Re: Given sequence A_k, k=[1,n] find min{A_k} k=[i,j] in O(logn) time with O(n) memory

2014-07-26 Thread Gene
On Wednesday, July 23, 2014 8:41:33 AM UTC-4, bujji wrote: > > Suppose that we are given a sequence of n values x1, x2, ..., xn and seek > to > quickly answer repeated queries of the form: given i and j, find the > smallest value > in xi, . . . , xj . > > Design a data structure that uses O(n) s

[algogeeks] Re: What is the algorithm for this problem

2014-07-09 Thread Don
// This function returns the number of hints required to // determine the order of the cards. // Parameter int c[n] specifies n cards which are provided // in an unknown order. Each card is represented as a 10-bit field // with two bits set, one representing the color of the card and the // other r

[algogeeks] Re: What is the algorithm for this problem

2014-07-09 Thread Don
Here is a fairly simple way to find a solution. Make a list of each pair of the n cards which have been selected. This list can include up to 300 pairs. Represent each card as a 10-bit value where each bit represents one particular color or value. Thus, each card will have two bits set. Each pa

[algogeeks] Re: What is the algorithm for this problem

2014-07-08 Thread Don
There are a total of 10 hints which can be asked for. If you ask for 4 colors and 4 values, you can deduce the remaining color or value by a process of elimination, so the most hints you will ever need is 8. You may not need all eight hints, if every card can be distinguished from every other

[algogeeks] Re: What is the algorithm for this problem

2014-07-07 Thread Don
As soon as you get one hint, the number of orders drops greatly. Your first question should be to ask about the color or value which occurs closest to n/2 times. When you ask about that, the number of possible orders will be much smaller, and you can continue with just that list. The problem was

[algogeeks] Re: What is the algorithm for this problem

2014-07-02 Thread vikas
Don, if you are talking about cards ordering then it will be n! which looks pretty high to compute ( consider even for n=10). and then for every count , you will need to compute every single color and values , i.e. worst case will be 25 n! ~ O(n!) . Can we do better ? On Wednesday, 2 July 2014

[algogeeks] Re: What is the algorithm for this problem

2014-07-01 Thread Don
Initially there are 5! = 120 possible orders for the cards. You should ask for the hint which will reduce that number by the largest amount. So in your example above, asking which cards have value 1 would not reduce the number at all. Asking which card is Green would reduce the possible orders

[algogeeks] Re: Solving complicated Tree construction algorithm for Spatial Partioning

2014-06-10 Thread nurabha
Here is brief list of background concepts needed to understand the problem - Space Filling Curves (SFC) : Morton codes are one particular kind of SFC implmeentation. Gray code and Hilber code are two more types of SFCs that can be generated - Binary tree and traversal - Prefix trees - Basic sort

[algogeeks] Re: Solving coin change problem with limited coins.

2014-05-20 Thread s khadar
The main difference between the standard CC algo, and the one with limited coin supply is the maximum value that we can form with the given coins. For example : In stranded CC coins[] = {1,2,3} then we can can form denominations to any value(assuming that coin with 1 value will always be the

Re: [algogeeks] Re: Shortest path in grid with dynamic programming.

2014-05-20 Thread Don
BFS might be faster, though. Don On Tuesday, April 22, 2014 1:11:00 AM UTC-4, bujji wrote: > > Hi Don, > At most we can reach a point from 4 adjacent points. So, > time complexity will be O(XY) only. > > -Thanks, > Bujji. > > > On Mon, Apr 21, 2014 at 1:38 PM, bujji jajala > > wrot

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-20 Thread Don
Shashwat, very nice. Don -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-19 Thread Don
In my solution, the line which reads: if (sum < result) sum = result; Should read if (sum < result) result = sum; Don On Friday, May 16, 2014 11:51:52 PM UTC-4, Shashwat Anand wrote: > > @Don > int coins [] = {1, 3, 5}; > int cnt [] = {7, 3, 1}; > int S = 9; > Your code returns 9, for the

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-16 Thread Shashwat Anand
@Don int coins [] = {1, 3, 5}; int cnt [] = {7, 3, 1}; int S = 9; Your code returns 9, for the aforementioned test case. Should not it return 3 ? Here is my take which takes O (|number of denominators| x |S| x |maximum count for any coin|) time and O (|number of denominators| x |S|) time. It is

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-16 Thread Don
If you find a way to do that for more than a few coins I'd be interested in seeing it too. Don On Thursday, May 15, 2014 3:00:04 PM UTC-4, atul007 wrote: > > @Don : i am intersted in DP bottom up approach with less time complexity. > solving it recursively is a simpler approach... > On 15 May 201

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-15 Thread atul anand
@Don : i am intersted in DP bottom up approach with less time complexity. solving it recursively is a simpler approach... On 15 May 2014 22:25, "Don" wrote: > How about this: > > const int N = 6; > unsigned int coins[N] = {100,50,25,10,5,1}; > unsigned int count[N] = {2, 1, 1, 5, 4, 10}; > int be

[algogeeks] Re: Solving coin change problem with limited coins.

2014-05-15 Thread Don
How about this: const int N = 6; unsigned int coins[N] = {100,50,25,10,5,1}; unsigned int count[N] = {2, 1, 1, 5, 4, 10}; int best = 10; int minCoins(int s, int f=0, int d=0) { if (d == 0) best = s; // It can never take more than s coins if (s < 1) return 0; // No coins required

Re: [algogeeks] Re: Shortest path in grid with dynamic programming.

2014-04-22 Thread Don
Good catch. A function called "markShortestPath" ought to mark the shortest path, huh? Don On Monday, April 21, 2014 4:38:32 PM UTC-4, bujji wrote: > > > Nice solution. good. Looks like in your markShortestPath(int > i, int i, int d) function > you missed to set distance[i][j

Re: [algogeeks] Re: Shortest path in grid with dynamic programming.

2014-04-21 Thread bujji jajala
Hi Don, At most we can reach a point from 4 adjacent points. So, time complexity will be O(XY) only. -Thanks, Bujji. On Mon, Apr 21, 2014 at 1:38 PM, bujji jajala wrote: > Hi Don, > Nice solution. good. Looks like in your markShortestPath(int > i, int i, int d) f

Re: [algogeeks] Re: Shortest path in grid with dynamic programming.

2014-04-21 Thread bujji jajala
Hi Don, Nice solution. good. Looks like in your markShortestPath(int i, int i, int d) function you missed to set distance[i][j] = d; as first statement. It looks like time complexity of this program is greater than O(XY). It depends on number of multiple paths to a point with dif

[algogeeks] Re: Shortest path in grid with dynamic programming.

2014-04-21 Thread Don
bool bad[X][Y]; int distance[X][Y]; void markShortestPath(int i, int i, int d) { if ((i >= 0) && (j >= 0) && (i < X) && (j < Y) && (distance[i][j] > d) && !bad[i][j]) { markShortestPath(i+1, j, d+1); markShortestPath(i-1, j, d+1); markShortestPath(i, j+1, d+1); m

[algogeeks] Re: Max difference of Monotonic Pair in An Array

2014-04-21 Thread Don
// The result will always include the smallest value of A[i] where i is less than j, // so just keep track of that minimum value as you scan through the array. int findPair(int *A, int N) { min = A[0]; max = 0; for(j = 1; j < N; ++j) { if ((A[j] - min) > max) max = A[j] -

[algogeeks] Re: Shortest path in grid with dynamic programming.

2014-04-21 Thread Don
Create a matrix distance[x][y] and set all values to a large number. This will represent the distance to travel to the destination on the shortest route. Now set the distance at the destination to zero. Set all adjacent locations to one, and repeat the process recursively, always setting valid ad

Re: [algogeeks] Re: Calculating C(n.r)

2014-04-09 Thread kumar raja
Thanks for the idea. On 9 April 2014 10:25, Dave wrote: > What you want to do is automate the process of cancelling common factors > that you would do if you were calculating nCr by hand. Fill an array a[] > with the numerator terms, n, n-1, n-2, ..., n-r+1, and a second array b[] > with the de

[algogeeks] Re: Calculating C(n.r)

2014-04-09 Thread Don
Very nice solution. Don On Wednesday, April 9, 2014 12:55:43 AM UTC-4, Dave wrote: > > What you want to do is automate the process of cancelling common factors > that you would do if you were calculating nCr by hand. Fill an array a[] > with the numerator terms, n, n-1, n-2, ..., n-r+1, and a se

[algogeeks] Re: Calculating C(n.r)

2014-04-08 Thread Dave
What you want to do is automate the process of cancelling common factors that you would do if you were calculating nCr by hand. Fill an array a[] with the numerator terms, n, n-1, n-2, ..., n-r+1, and a second array b[] with the denominator terms, 1, 2, 3, ..., r. Inside a double loop with j an

[algogeeks] Re: Calculating C(n.r)

2014-04-08 Thread Don
Note that my example is for C(n,r), but you can use the same method for your second formula. Just add up the logs of whatever you multiply in the numerator and subtract the logs of the factors of the denominator. Then the result is exp of the resulting sum. Don On Tuesday, April 8, 2014 2:15:0

[algogeeks] Re: Calculating C(n.r)

2014-04-08 Thread Don
Use the fact that a*b*c*d = exp(log a + log b + log c + log d) double sum = 0.0; double x; for(x = n-r+1.0; x <= n; x += 1.0) sum += log(x); for(x = 2; x <= r; x += 1.0) sum -= log(x); result = exp(sum); Don On Tuesday, April 8, 2014 2:06:47 PM UTC-4, kumar raja wrote: > > Hi all, > > I

Re: [algogeeks] Re: Implement lastindexofastring(String s1,String s2)

2014-04-07 Thread Carl Barton
What I suggested is optimal and doesn't require you to reverse the strings. It's not hard to see that it takes O(n + m) which cannot be improved on. Additionally it works for any other search algorithm than KMP. On 7 April 2014 20:41, Dan wrote: > Depends on what language you are using??? > >

[algogeeks] Re: Implement lastindexofastring(String s1,String s2)

2014-04-07 Thread Dan
Depends on what language you are using??? Fortran has this capability built directly into it's standard Index() routine ( ie. it does what you might call a 'backwards' search). I imagine other languages have a similar capability. If not, and the strings are not huge memory hogs... or if y

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-31 Thread Don
The only square is found when s=2. Your program will look at s=3 and not find a square, so it will never find the square. Try it and you will see what I mean.. Don On Monday, March 31, 2014 2:42:13 PM UTC-4, atul007 wrote: > > @Don: what is the point of considering s=2 when we have already fou

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-31 Thread atul anand
@Don: what is the point of considering s=2 when we have already found s=3.As question says find "the maximum subsquare". Which is of size 3 and this the expected outcome. On Mon, Mar 31, 2014 at 11:28 PM, Don wrote: > 00 > 00 > 010100 > 011100 > 01 > 00 > > In this case, when i

[algogeeks] Re: explanation of solution required.

2014-03-31 Thread Don
The sort is what makes this O(n*log n). The processing after the sort is O(N). So to describe the algorithm, after sorting A, it steps through the sorted array, determining what the value of K would have to be at that point such that setting the remaining values to K would cause the sum to be S

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-31 Thread Don
00 00 010100 011100 01 00 In this case, when i and j are 1, your algorithm will set s = 3. The if statement will fail, and it will never notice that it could have formed a square with s=2. Don On Sunday, March 30, 2014 9:49:21 AM UTC-4, atul007 wrote: > > @don : According to q

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-30 Thread atul anand
@don : According to question we want to find "the maximum subsquare". can you give me test case for which this wont work? On Fri, Mar 28, 2014 at 9:41 PM, Don wrote: > No, that is not the same. > It won't find a square smaller than s. > Don > > > On Thursday, March 27, 2014 2:56:29 AM UTC-4,

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-28 Thread Don
No, that is not the same. It won't find a square smaller than s. Don On Thursday, March 27, 2014 2:56:29 AM UTC-4, atul007 wrote: > > @Don : your algo time complexity is O(n^2) > > It can be reduced to this :- > > // Now look for largest square with top left corner at (i,j) > for(i = 0; i < n

Re: [algogeeks] Re: maximum subsquare such that all four borders are filled black

2014-03-27 Thread atul anand
@Don : your algo time complexity is O(n^2) It can be reduced to this :- // Now look for largest square with top left corner at (i,j) for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) { s = Min(countRight[i][j], countDown[i][j]); if (countRight[i][j] && countDown[

Re: [algogeeks] Re: strictly sorting by adding or subtracting a range of numbers

2014-03-26 Thread ybbkrishna
@googlegroups.com Reply To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: strictly sorting by adding or subtracting a range of numbers @bhargav : could you please explain your algorithmn On 3/25/14, bhargav krishna yb wrote: > Even i completed it :). It was from one of the coding challen

Re: [algogeeks] Re: strictly sorting by adding or subtracting a range of numbers

2014-03-25 Thread atul anand
@bhargav : could you please explain your algorithmn On 3/25/14, bhargav krishna yb wrote: > Even i completed it :). It was from one of the coding challenges... > > public class Hill { > > /** > * @param args > */ > public static void main(String[] args) { > // TODO Auto-generated method stub > In

Re: [algogeeks] Re: strictly sorting by adding or subtracting a range of numbers

2014-03-24 Thread bhargav krishna yb
Even i completed it :). It was from one of the coding challenges... public class Hill { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Integer[] l = new Integer[] {15,5, 4, 3, 2, 8}; hill(l); } public static void hill(Integer[] l) { int max = 0; f

[algogeeks] Re: strictly sorting by adding or subtracting a range of numbers

2014-03-24 Thread Dan
I just stumbled upon this one (I know, a little late). At least this way... it's too late to be helpful if it was a Homework assignent. :-) This is one of those problems that, at first, appears difficult, but , upon closer inspection, turns out to have a very straight forward (elegant?) s

Re: [algogeeks] Re: DISTINCT Permutations ( Not Easy)

2014-03-11 Thread navneet singh gaur
formatting changes . void permute(char *a, int i, int n) { int j; if (i == n) printf("%s\n", a); for (j = i; j <= n; j++) { if(a[i] != a[j]) check before swapping if you are swapping different elements or not, if not then don't. { swap(a[i], a[j]);

Re: [algogeeks] Re: DISTINCT Permutations ( Not Easy)

2014-03-11 Thread navneet singh gaur
void permute(char *a, int i, int n) { int j; if (i == n) printf("%s\n", a); for (j = i; j <= n; j++) { if(a[i] != a[j]) { swap(a[i], a[j]); //just check before swapping if you are swapping different elements //or

[algogeeks] Re: Data structure question

2014-03-09 Thread SVIX
1- question seems to be a little too vague... if it's a mail server application, I'm guessing you would use some kind of persistent storage... maybe a no-sql solution like cassandra... u could use a tale with the user ID and mail status as key to store mails... 2- priority queues, maybe 3- a s

[algogeeks] Re: Integer partition problem - DP

2014-03-05 Thread Dave
See http://en.wikipedia.org/wiki/Partition_(number_theory). On Saturday, March 1, 2014 10:25:57 AM UTC-6, kumar raja wrote: > > Given an integer how many number of ways u can partition the number? > > e.g. 3 can be written as 3,1+2,1+1+1 > and 4 can be written as 4, 1+1+1+1,2+2,1+3,1+1+2 >

[algogeeks] Re: [Adobe]Generate all possible combinations (of r elements) inside an array of size N

2014-02-27 Thread Ziklon
1.- if you use bitmask can be easy solved 2.- second aproach is create un recursion string func(int idx, int cnt){ if(cnt==r)return "";; string ans = func(idx+1, cnt); if(cnt > Generate all possible combinations (of r elements) inside an array of > size N > E.g. arr [] = {2,8,14} All po

[algogeeks] Re: Permuations with stack constraints

2014-02-21 Thread Dave
@Kumar: As a point of interest, the number of valid sequences of n pushes and n pops is C(3), the third Catalan Number. See, e.g., http://en.wikipedia.org/wiki/Catalan_number for details. Dave On Thursday, February 20, 2014 12:27:35 PM UTC-6, kumar raja wrote: > Hi all, > > Here is a permuatat

Re: [algogeeks] Re: Find 3 digit number.

2014-02-13 Thread Shashwat Anand
@Don, amazing solution. Let us say, I don't have the insight to see the greedy solution mentioned by @Don there is an obvious dp solution for the general case. typedef long long int64; const int64 LINF = (int64) 1e16 + 5; map memo; int64 solve (int n) { if (n < 10) return n; if (memo.c

[algogeeks] Re: Find 3 digit number.

2014-02-13 Thread bhargav
> > import java.util.ArrayList; > import java.util.Collections; > import java.util.List; > import java.util.Scanner; > > > public class PrimeFactors { > > /** > * @param args > */ > public static void main(String[] args) { > Scanner sc = new Scanner(System.in); > int n = sc.nextInt(); > List

[algogeeks] Re: Generate random number from 1 to 10.

2014-02-12 Thread SVIX
Thanks for the explanation Don! It looks like I need better math-foo to completely understand your explanation... On Tuesday, February 11, 2014 10:07:05 AM UTC-8, Don wrote: > > > It can be shown mathematically that if you use a multiplier A such that > A*2^15-1 and A*2^16-1 are both prime, you

[algogeeks] Re: Generate random number from 1 to 10.

2014-02-11 Thread Don
It can be shown mathematically that if you use a multiplier A such that A*2^15-1 and A*2^16-1 are both prime, you get a sequence with period A*2^15. With A=63663 you get a sequence of nearly two billion. If A was larger than 2^16, the multiplication would result in overflow in some cases, so t

[algogeeks] Re: Generate random number from 1 to 10.

2014-02-10 Thread SVIX
:) true... that was silly of me.. I was too quick to post... anyway, the point I was trying to understand was why this specific combination of operations would produce good randomness... Running the original solution you posted a million times (with the max limit set to 1000), below is the freq

Re: [algogeeks] Re: Generate random number from 1 to 10.

2014-02-10 Thread Don
https://groups.google.com/forum/#!original/comp.lang.java.programmer/Z8lfFIDhS7k/wbPLDldPSSgJ The Multiply With Carry generator is ok for some purposes. There are generators with longer periods and better statistical properties, but they are more complicated. The link I provided has code for a 6

Re: [algogeeks] Re: Generate random number from 1 to 10.

2014-02-07 Thread atul anand
@don : awesome +1 . I was not aware of George Marsaglia's Multiply With Carry generator. But it is soo clll . If you have any good link for its proof or explanation of the idea behind it then please mention it. I never knew generating random number can be few lines of code :) Thanks :)

Re: [algogeeks] Re: Generate random number from 1 to 10.

2014-02-07 Thread Don
A random generator will not always (or even usually) produce a permutation of the possible values before repeating. If you call my function 10 million times and tally up the results, you will get a distribution with about a million of each value, as close as you would expect for a random sample

  1   2   3   4   5   6   7   8   9   10   >