Question about data structure

I was asked the following question: How would you save the data below (which data structure will be selected):

A-1-2-3-4-5-6

|

B-7-8-9-10-11

|

C-12-14-15-16-17

My annas: Since it looks like a bunch of lists with nodes connected to each other. Use two node types, one identifier for the regular node type, with the following definition:

Struct node1
{
int val;
struct node*next;
};
// to store the numerical part of the data

struct node2
{
 int val;
struct node *down;
struct node* next;
};
//this is the heads of each list.. for the alphabet part of the question.

Interviewer Response: This is the best data structure you can think of. How abt in terms of crawl and memory needed for each node?

My answer to this: We can intersect better if we create some kind of hash table.

My question to you, comrades: Can we work better? Is there a better way to store this data type?

we assume that the data is all numbers (even those of each node head) and non-serial with repetitions. What would be the correct answer? Finding Answers in C / C ++

+3
6

, , . , . , . .

+6

, .

char 6 node, . , , . , char , , .

+1

# string/int:

Dictionary<string,int[]> 
+1

(Java ArrayLists)

0

" #s N N + x", ;)

0

, . , , , - . , . , , . , , , .

0
source

Source: https://habr.com/ru/post/1725197/


All Articles