Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:41:39+00:00 2026-06-08T07:41:39+00:00

I am very new to the Objective-C language and I was asked a question

  • 0

I am very new to the Objective-C language and I was asked a question in the interview that I was not able to answer.

I tried a lot of approaches and logic to no success. Here looking for an answer:

The question was:

 - (NSArray *)reorderTheArraysAndMergeThemInDescendingOrder:(NSArray *)firstArray and:(NSArray *)secondArray

Both the provided arrays in the argument are already sorted in ascending order.

My task was to provide an array as the return variable which will have all the unique elements of both firstArray and the secondArray and will have them in theh descending order. I was not allowed to use the inbuilt sorting functionality of Objective-C (that was the way I have been doing it ever since I am in this field). My variables may only be primitives (the result will be an integer array of course.).

I am new to the whole programming scene altogether and a good answer here will be MUCH appreciated.

Shukaku

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:41:41+00:00Added an answer on June 8, 2026 at 7:41 am

    Since the provided arrays are sorted in ascending order, this question is pretty-much related to the classic algorithm of Mergesort (have a look at it if you’ve never heard of it, this is a classic).

    Since you’re array contain only primitive data types, they can be compared using <

    The code that interest you would look like

    - (NSArray *)reorderAndMergeReverse:(NSArray *)array1 and:(NSArray *)array2{
    
        NSMutableArray *result = [NSMUtableArray array];
    
         int i = array1.count-1;
         int j = array2.count-1;
    
         while (result.count < array1.count+array2.count){
    
            if ([array1 objectAtIndex:i] > [array2 objectAtIndex:j]){
                 [result addObject:[array1 objectAtIndex:i]];
                 i--:
            } else {
                [result addObject:[array2 objectAtIndex:j]];
                 j--:
            }
    
         }
         return result;
    }
    

    I am not sure as to whether you want to remove duplicates, your question is not that clear, would you mind telling me if so so that i can improve my code ?
    Edit : Did it anyway : since you’re array is sorted, duplicates are just next to each other, so it might be easy not to add them in the first place;

    - (NSArray *)reorderAndMergeReverse:(NSArray *)array1 and:(NSArray *)array2{
    
        NSMutableArray *result = [NSMUtableArray array];
    
         int i = array1.count-1;
         int j = array2.count-1;
         int k = 0;
    
         while (i>=0 || j>=0){
    
            if ([array1 objectAtIndex:i] > [array2 objectAtIndex:j]){
                 if ([array1 objectAtIndex:i] != [result objectAtIndex:k]){
                     [result addObject:[array1 objectAtIndex:i]];
                     k++;
                 }
                 i--:
            } else {
                if (array2 objectAtIndex:j] != [result objectAtIndex:k]){
                       [result addObject:[array2 objectAtIndex:j]];
                       k++;
                 }
                 j--:
            }
    
         }
         return result;
    }
    

    Edit : There are some errors in that code, because i could become negative and afterward be used in objectAtIndex:, this is just meant to demonstrate the idea, not to give an out-of-the-box code solution

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I am very new to Objective C and iPhone programming. Now that
Sorry if the question isn't correct, I'm very new in Objective-C. I understand why
I am very new to Objective-C and haven't had a lot of experience with
My method + (void) initialized is not called and I'm very new in Objective
I am very new new to iPhone app development and not able to correct
I'm very new to objective C. I followed the tutorial for integrating Facebook to
I'm very new to Objective-C, and am having some beginner issues. I have an
please help me, i'm very new in objective-c i've got 2 simplest classes (bellow
I am very new at iOS and objective-c development, so I am struggling with
Apologies or asking what is probably a very straightforward question, but I'm new to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.