baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
I need some advice regarding the following problem.
Problem:
Let A be an array of integers where x,y is an index 0 < x,y < |A|-1. Given x find y s.t. A[y] = z and A[y] is the first z-value element encountered starting from A[x] to A[y] where x>y .Example:
A=[2 3 43 12 46 7 8 9 90 4 34 4 4]Cheers Baxy
Given that x = 5 the A[5] = 7 and given that z =4 then y=9. The problem is how to do this in constant time. How to preprocess the array A so that when x=5 and z=4 are given as an input result that is received is y=9. Does anyone have any suggestions ??
UPDATE:
YES that is it , you see you got it :) :
dave_the_m"Given an array A, an index i, and a value v, find the smallest index j such that j > i and A[j] == v"
UPDATE:2
well if it is a CS homework than please provide a solution because then i missed that class and therefore i don't know the solution and am a bit puzzled on how to get one. Plus, I don't want to do a Spares table for this
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Index finding problem
by dave_the_m (Monsignor) on May 13, 2012 at 12:16 UTC | |
|
Re: Index finding problem
by BrowserUk (Patriarch) on May 13, 2012 at 14:20 UTC | |
|
Re: Index finding problem
by Anonymous Monk on May 13, 2012 at 12:20 UTC |