• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Returning index of a member in a Cartesian Product

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I'm trying to do some of the code golf challenges and seem to be having problems understanding their interface. One of the questions on there goes as follows:
Given two lists e.g. A= [1,2,3] and B= [4,5] and a tuple (i,j) where i indicates A[i] and B indicates B[j], with A,B known, I needed to write a program that would return the index of a member in the Cartesian Product of A and B (lets call this C) according to (i,j). And if th inputs are invalid return -1

eg: if input is

[1,2,3]
[4,5]
(2,1)

output should be 5

and if input is

['a','b','c']
[1,2,3]
(2,1)

output should be -1

and I was given a starter code.





Here is my code that does not seem to be working on the platform...




Any insights on how to make it work will be greatly appreciated. If i need to use the starter code differently?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, did you got the solution for this now?
I am trying to solve this, but I didn't get up to the solution. Can you also please share the link to the question?
 
Marshal
Posts: 74048
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think you have one of those problems you need to solve on paper before you try any code. What is the logic for finding an index? Have you drawn a diagram of the Cartesian product of those two Lists?

. . . i indicates A[i] and B indicates B[j] . . .

Did they really say that? That is very unclear. I presume it means that i is an index in the first List and j and index in the second List. Did they say whether they were using 1‑based indexing, or 0‑based as used by Java┬« Lists and arrays?

. . . I was given a starter code.

They didn't say that way to read files is badly out of date?
 
Saloon Keeper
Posts: 1316
40
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... I was given a starter code.

Campbell Ritchie wrote:
They didn't say that way to read files is badly out of date?



A lot of sites, especially ones that support many different languages and that have been around for a while, give you starter code or "framework I/O code" that is pretty out of date.

In some cases, the user isn't even allowed to edit the starter code, in others, it would be allowed but the user is expected to focus on the code called by the starter code, rather than edit it.

There are a handful of problems where the starter code itself is actually fatally flawed, and MUST be changed (at least in a specific chosen implementation language) to get the solution to work, this is surprising when the previous 20 problems you'd done on that site neither required nor allowed you to change that part!

I'd missed this post originally, and agree that the Starter Code itself isn't very good for this problem, and apparently could be changed on this site, but that is just a guess without knowing which site it comes from.

I mentioned this stuff because in my experience, a lot of the sites DO lock down the starter code, possibly to prevent cheating and possibly to focus the user on the part of the problem they are required to solve, and if we thought it was bad enough, and the site was popular enough to make a big difference, the people to mention this to would be those running the site, as the user has little or no control over it.

I find the problem description here rather inscrutable, completely independent of starter code or the language the solution is to be implemented in.
It is not clear if the original problem statement is this difficult to read or the OP's paraphrasing made it worse.

Poorly worded problem statements are an unpleasant reality.  I had a Real one yesterday for an interview coding challenge.
The time limits are very tight, so you really can't spend too much time in "hmmmm...." mode or you have no chance of finishing.
Everything is automated and auto-graded (some let you see your grade, some do not) and there is no opportunity to ask for clarifications during the exam, you have to just see how many points your solution gets, or worse still, not see it as this is only reported to the employer.

This was posted here in "Java in General" but the real problems belong in the topic "Help, I am facing an automated test on Platform X!" because many of the usual ways of dealing with these issues "Calmly ask the interviewer for a clarification, specify the two possible interpretations you are having trouble deciding between" are essentially useless in these situations.  You have to guess, with time pressure, sometimes in ways that will give you no hope for recovery if you guess wrongly.  Fun stuff, but hardly Java-specific.

This site is apparently just for practice, not a real test, but the same issues tend to come up with differences just in the consequences.

They normally allow you to provide Feedback (including complaints about harmfully ambiguous parts of the problem statements) after the fact, and in a way that is unlikely to affect your score, tho it may help those doing a problem / taking a test after you.

Lastly, it feels like most of the sites that are intended for practice, rather than a graded score, have an adjacent forum thread on-site discussing aspects of the problem and possible solutions.
Within those, they can be broken down into those that let you access that straight away, and those that only let you see that information for a question after you have successfully answered it, which is lees than helpful in the event that you find the problem statement inscrutable.
 
reply
    Bookmark Topic Watch Topic
  • New Topic