Search Your Question

Equilibrium Problem - Left and right side and top and bottom side sum of any point are same in matrix


Problem Description :

#import <Foundation/Foundation.h>


int leftArraySum(NSMutableArray *A,int n)
{
    NSInteger sum  = 0;
    for(int i=0;i<n;i++)
    {
        sum += [[A objectAtIndex:i] integerValue];   
    }
    return sum;
}

int reightArraySum(NSMutableArray *A,int n)
{
     NSInteger sum  = 0;
    for(int i=n+1;i<[A count];i++)
    {
        sum += [[A objectAtIndex:i] integerValue];   
    }
    return sum;
}

int topArraySum(NSMutableArray *A,int n)
{
     NSInteger sum  = 0;
    for(int i=0;i<n;i++)
    {
        sum += [[A objectAtIndex:i] integerValue];   
    }
    return sum;
}

int bottomArraySum(NSMutableArray *A,int n)
{
     NSInteger sum  = 0;
    for(int i=n+1;i<[A count];i++)
    {
        sum += [[A objectAtIndex:i] integerValue];   
    }
    return sum;
}

int solution(NSMutableArray *A) {
    // write your code in Objective-C 2.0
 
    NSMutableArray *rowArr = [A objectAtIndex:0];
    int colCount = [rowArr count];
    int rowCount = [A count];
 
    NSMutableArray *arrRowSum = [[NSMutableArray alloc] initWithCapacity: rowCount];
    NSMutableArray *arrColSum = [[NSMutableArray alloc] initWithCapacity: colCount];
 
    for(int i=0;i<rowCount;i++)
    {
        NSArray *colArr = [A objectAtIndex:i];
        NSNumber * sum = [colArr valueForKeyPath:@"@sum.self"];
        [arrRowSum insertObject:sum atIndex:i];
    }
 
    for(int i=0;i<colCount;i++)
    {
     
        NSInteger sum = 0;
        for(int j=0;j<rowCount;j++)
        {
           sum +=  [[[A objectAtIndex:j] objectAtIndex:i] integerValue];
        }
        NSNumber *sumVal = [NSNumber numberWithInt:sum];
        [arrColSum insertObject:sumVal atIndex:i];
    }
 
    int result = 0;
    for (int i=1;i<rowCount;i++)
    {
        int left = leftArraySum(arrRowSum,i);
        int right = reightArraySum(A,i);
        if(left  == right)
        {
            for(int j=0;j<colCount;j++)
            {
                int top = topArraySum(A,j);
                int bottom = bottomArraySum(A,j);
                   if(top == bottom )
                {
                    result = i+j;
                    break;
                }
            }
        }
    }
 
    return result;
}


What types of feature google map provide to developers?

Ans : 

Google map features :
  • Plotting places Near Me. Like near by hospitals, restaurants, temples
  • Direction ( route ), Distance, Travel time, Live traffic
  • Street view for 3D location
  • Geofencing
  • Live tracking location
  • Get current location
  • Put markers on various places
Alternatives of Google map api :
I am using MapMyIndia api due to high cost of Google map apis. I have also implemented here map. Both are nice.

There are two versions of here-map, free and premium. Premium here map service is better than free here map service. I have implemented live tracking of car, replay route, using both apis.

What are collection types in objective C and Swift?

Ans : 

In  iOS, there are 3 collection types

i. Array 
ii. Dictionary 
iii. Set.

There are two types of collection types. Mutable and Immutable. Mutable can be changed but immutable can not be changed once initialised.

Q. How to check nil keys in dictionary?
A. There is not any nil keys in dictionary.

Determine index of one integer in another integer - online programming question

Problem Description : Determine index of one integer in another integer

i.e If input A = 23,B = 1472367 then Output : 3 . Because '23' is 3rd index in '1472367'.

Asked in Company : Futurescape Technologies Pvt Ltd  via Codility.com

Ans : 

#import <Foundation/Foundation.h>
// you can also use other imports, for example:
// #import <SomeLibrary/SomeFile.h>

// you can write to stdout for debugging purposes, e.g.
// printf("this is a debug message\n");

int solution(int A, int B) {
    // write your code in Objective-C 2.0
    NSString *strA = [NSString stringWithFormat:@"%d",A];
    NSString *strB = [NSString stringWithFormat:@"%d",B];
 
   NSRange range =   [strB rangeOfString:strA];
   if(range.location == NSNotFound)
   return -1;
   else
   return range.location;
}


Do you like to use storyboard? Why? Can more than 1 storyboard allowed?

Ans : I like to use storyboard.

I am using storyboard due to advantage over XIB : See here

Yes, we can use more than 1 storyboard. We can make different storyboard for different features in same project.

Navigating from one storyboard to another storyboard :

1. Using segue :

  • Drag & Drop storyboard reference
  • Give name and assign viewcontroller (to which we want to navigate)
  • Give segue from viewcontroller to storyboard reference.
2. Using coding :


var anotherStoryboard = UIStoryboard(name: "another", bundle: nil)
var vc: UIViewController = anotherStoryboard.instantiateViewController(withIdentifier: "loginView")
present(vc, animated: false)