## Brocade Interview Question for Software Trainees

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

The idea is to use Merge function of Merge sort.

Create an array arr3[] of size n1 + n2.
Simultaneously traverse arr1[] and arr2[].
Pick smaller of current elements in arr1[] and arr2[], copy this smaller element to next position in arr3[] and move ahead in arr3[] and the array whose element is picked.
If there are remaining elements in arr1[] or arr2[], copy them also in arr3[].

Comment hidden because of low score. Click to expand.
0
of 0 vote

This is how I'd solve that, considering arrays a and b to merge to c

check one element from a and b and add the min to c until one of the arrays runs out of elements

add remaining elements from a or b to c

``````fun main() {
val a = arrayOf(1, 3, 5, 7, 8, 9)
val b = arrayOf(2, 4, 6)
print("A = \${a.asList()}")
print("B = \${b.asList()}")

val c = Array(a.size + b.size) { 0 }

var i = 0
var j = 0
var k = 0
// find the min of a[j],b[j] and add it at c[k]
// until one of the arrays(a or b) is empty
while (i < a.size && j < b.size) {
if (a[i] < b[j]) {
c[k] = a[i]
i++
k++
} else {
c[k] = b[j]
j++
k++
}
}

// add remaining elements to c
while (i < a.size) {
c[k] = a[i]
i++
k++
}
while (j < b.size) {
c[k] = b[j]
j++
k++
}

print("C = \${c.asList()}")
}``````

note: i contains position of current element in A similarly j for B and k for C

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
{"ft_lang_label":"__label__en","ft_lang_prob":0.77708817,"math_prob":0.9397116,"size":1296,"snap":"2021-31-2021-39","text_gpt3_token_len":416,"char_repetition_ratio":0.123839006,"word_repetition_ratio":0.04528302,"special_character_ratio":0.36882716,"punctuation_ratio":0.097222224,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97110903,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-29T02:16:14Z\",\"WARC-Record-ID\":\"<urn:uuid:0f9b2f32-c3ee-48db-aa58-915a7a9ed680>\",\"Content-Length\":\"25562\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:981c8d86-a897-42bf-86ed-7ea43f08f3e6>\",\"WARC-Concurrent-To\":\"<urn:uuid:0bce04bd-664d-4512-ba24-182a8d69e953>\",\"WARC-IP-Address\":\"216.239.32.21\",\"WARC-Target-URI\":\"https://careercup.com/question?id=5720840163819520\",\"WARC-Payload-Digest\":\"sha1:QXVQJDD4CJ7QIODGJJ546BXTFTS5K6TJ\",\"WARC-Block-Digest\":\"sha1:X4R5DMCQTXYZ4BBGU4NAFMQB7CB3TI7C\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780061350.42_warc_CC-MAIN-20210929004757-20210929034757-00706.warc.gz\"}"}