Hi guys, i have 2 vector needed merge. How can I find min dictionary order of vector after merge.
ex : A = {2, 3} B = {4, 5}
one of satis way is : {2, 4, 5, 3}, opposite {3, 2, 4, 5}, {3, 2, 5, 4} is not.
| # | User | Rating |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 143 |
| 7 | Errichto | 139 |
| 8 | adamant | 136 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
Hi guys, i have 2 vector needed merge. How can I find min dictionary order of vector after merge.
ex : A = {2, 3} B = {4, 5}
one of satis way is : {2, 4, 5, 3}, opposite {3, 2, 4, 5}, {3, 2, 5, 4} is not.
| Name |
|---|



if you mean a queue , then it is mergesort isn't it
No in this case the vectors are sorted but they may not be. I think what he is asking is the lexicographically smallest merging where the relative order of each element from each vector doesn't change. Eg:- a = {5, 1}, b = {2, 6} the answer is {2, 5, 1, 6}
But wouldn't $$$[2,3]$$$ and $$$[4,5]$$$ result in $$$[2,3,4,5]$$$ then? I think OP needs to clarify this
yes, for sure. I was also confused on this, but he/she says "one of satis way is ..." hard to decode tbh :)
{2, 3, 4, 5} is the answer we need :v
The way to solve this is:
Think of the vectors as queues, and greedily pop from the queue with smaller front value.
But how to handle duplicates?
a concat ba concat bin O(1) which will tell us which queue to pop fromthank u, is it O(n)
bonus : {2, 3, 4, 5} is the answer of ex test cases
then maybe just do a greedy thing like having the tops out and compare and choose
how about hashing and binary search :v
Well, maybe binary search could work, but it doesn't make the solution any easier. There is a greedy two-pointers way to solve this problem in $$$O(n+m)$$$.
but when a[i] = b[j], which element should we get
advance both pointers until the two pointers point to a different character. choose the lexicographically smaller side (segment).
ex) assume we have two strings $$$\text{bbbbabbbbb}$$$ and $$$\text{bbbbcbbbbb}$$$. Now the first difference happens on $$$\text{a}$$$ and $$$\text{c}$$$, so you can append $$$\text{bbbba}$$$ to the answer, move the pointer on $$$\text{bbbbcbbbbb}$$$ to the previous position, and keep going. answer will be $$$\text{bbbbabbbbbbbbbcbbbbb}$$$.
tks u, it look like hash but complex O(n)
Is it SPOJ MINSEQ?