Understand "Merge two sorted linked lists" on hackerrank - linked-list

(migrated from Code Golf)
The question comes from the HackerRank problem Merge two sorted linked lists:
Sample Input
1
3
1
2
3
2
3
4
Sample Output
1 2 3 3 4
Explanation
The first linked list is: 1→3→7→Null
The second linked list is: 3→4→Null
Hence, the merged linked list is: 1→2→3→3→4→Null
I have two questions:
How does the sample input correspond to the explanation section? There is no "7".
In the explanation,
"The first linked list is: 1->3->7->Null"
but in the merged list there is no "7". Why does "7" disappear?

It's a mistake. The first linked list is: 1→2→3→Null

Related

Weighted lottery [duplicate]

This question already has answers here:
Repeat whole row N times based on column value in Google Sheets
(2 answers)
How to Repeat a Data Set (several columns) x times in Google Sheets [duplicate]
(1 answer)
Repeat range of items multiple times in Google Sheets
(5 answers)
Closed 5 months ago.
I need to create a weighted lottery where people can have multiple entries and the number of entries is based upon a series of questions. For each question they get right, they get an entry into the lottery.
In my head, I've got a table with the participants' names and their total number of points (entries), then I need some way to have a list of the names with their multiple entries. So if my initial table looked like this:
Name
Points
John
5
Larry
4
Andre
2
Mika
6
Then my output list would look like this:
Name
John
John
John
John
John
Larry
Larry
Larry
Larry
Andre
Andre
Mika
Mika
Mika
Mika
Mika
Mika
Then I could just use the default row leaders from the output table as the entry for the person and use a random number generator to pick numbers.
That being said, I'm open to other ideas.
Try this formula-
=QUERY(INDEX(FLATTEN(SPLIT(REPT(A1:A4&"#",B1:B4),"#"))),"where Col1 is not null")
REPT(A1:A4&"#",B1:B4) will repeat each cell value of A1:A4 as per number in B1:B4. Then Split and flatten with make them a vertical array (column). Query() will return all the values except nulls (if any).
To make it more dynamic you may try-
=QUERY(INDEX(FLATTEN(SPLIT(REPT(A1:INDEX(A1:A,COUNTA(A1:A))&"#",B1:INDEX(B1:B,COUNTA(A1:A))),"#"))),"where Col1 is not null")
And with new LAMBDA() functions.
=FLATTEN(SPLIT(JOIN("",BYROW(A1:INDEX(B1:B,COUNTA(A1:A)),LAMBDA(x,REPT(INDEX(x,1,1)&"|",INDEX(x,1,2))))),"|"))

Filter based on Unique Values that only match certain criteria

This may be beyond my skill level in Google Sheets, and it's certainly straining my brain to think through, but I have two columns out a large spreadsheet (30000 lines or so) that I need to find matches between unique values on one list, and non-unique but specific values ONLY on another list. That is, I would need the following list to return only the values on the left that had a 3 in the right column every time that value appears on the left, not just for a specific instance.
"Unique" Identifier (can repeat)
Value
1
2
2
3
3
2
4
2
5
3
6
2
1
2
2
2
3
2
4
2
5
2
6
2
I have the following formula from another couple answers mocked up, but it doesn't get me all the way there:=UNIQUE(FILTER(A2:A,B2:B>0))
How can I get it to exclude the ones that have, for instance, both a 2 and a 3 in the right column for the same value in the left column?
Edit: To put it in more real terms (I was trying to keep it abstract so I could understand the basics), I have a Catalog ID and a Condition for items, and need to find all Catalog IDs that only have Good copies, not any Very Good copies. This link should show what I want to achieve:
https://docs.google.com/spreadsheets/d/e/2PACX-1vSjenkDS2Mk3t4kTcDoJqSc8AV6ONu4Q17K1HPaIUdJkb7dhdnbAt-CzUxGO3ZoJISNpGajUtFTGz8c/pubhtml?gid=0&single=true
to return only the values on the left that had a 3 in the right column every time
try:
=UNIQUE(FILTER(A:A; B:B=3))
update 1:
=UNIQUE(FILTER(Sheet1!A:A; Sheet1!B:B="Good"))
update 2:
=UNIQUE(FILTER(Sheet1!A:A, Sheet1!B:B="Good",
NOT(COUNTIF(FILTER(Sheet1!A:A, Sheet1!B:B<>"Good"), Sheet1!A:A))))

Cleanse List of NCAAB Teams to show without mascot name (more details in description)

I have two ImportHTML functions in my sheet, pulling data from different websites. The result is two different (yet very similar) lists of NCAAB teams and their scores. I am trying to vlookup the scores in List 2 based on the school name (without mascot) in List 1. See below:
Example
List 1 = Indiana
List 2 = Indiana Hoosiers
Example 2
List 1 = Duke
List 2 = (3) Duke Blue Devils
Here is a link to a google sheets doc where I am working.
https://docs.google.com/spreadsheets/d/1nx5RaO5mSKVq_LlWTwrMtuHsqjb69W4_Rzan4Q5HjR0/edit?usp=sharing
Thank you & let me know if more info is needed,
Greg
I figured this out. Instead of "cleansing" list 2, I just created a reference table linking the name in list 1 to the name in list 2 and doing a vlookup off that.
Thank you.

How to divide an alphabetical list into 3 column alphabetical list

I have 2 google sheets, one with an alphabetical order names and numbers for each name like: Dean 1 1 1 1, Jacob 2 2 2 2, Kyle 3 3 3 3. I want to transfer all that into another google sheet that has 3 columns, in one is Dean, in one Jacob and in the other one Kyle. I'm trying to a formula that would see a match for their names and place 1 1 1 1 for Dean, 2 2 2 2 for Jacob and 3 3 3 3 for Kyle.
Photos:
You'll find the alphabetical list in one column in the "Project Automation Final Result" in https://docs.google.com/spreadsheets/d/1QrfqAOvIc4XnaJrxk0PMr7pmQp42q2b-V8Bqrzxuchw/edit?usp=sharing
The 3 columns alphabetical list in "Names lists" same link as above.
And I want to insert the Final Result in here https://docs.google.com/spreadsheets/d/1s5yBvEcGFvUiiJTc3K-kQLlCqeOupuGcvqJkZGDmjzY/edit?usp=sharing
Any ideas, suggestions help, thank you for your time.
use this:
=ARRAYFORMULA(IFERROR(VLOOKUP(A6:A,
IMPORTRANGE("1QrfqAOvIc4XnaJrxk0PMr7pmQp42q2b-V8Bqrzxuchw",
"Project Automation Final Result!A:F"), {2,3,4,5,6}, 0)))

Count matches between two columns on Google Docs

I have two columns that I want to test if any of their values matches and count how much of them. For example:
1 2
2 5
3 1
4 7
Should return two, since 1 and 2 are in both columns.
I've found that in excel I could do =SUMPRODUCT(A1:A4=B1:B4), but I can't find the same in Google Spreadsheet. I tried =ARRAYFORMULA(SUMPRODUCT(A1:A4=B1:B4)), but it didn't work.
Thanks for the help!
I think its strange to answer your own question, but since I found the solution..
I archieved it doing =ARRAYFORMULA(SUM(COUNTIF(A1:A4=B1:B4)))

Resources