### 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 :

• 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)

### What is multiplier and ratio in auto layout in ios?

Ans :

Difference between Multiplier and Ratio :

There is not any difference. Both are using for same purpose.

The Aspect Ratio is really just a convenient way to express the Multiplier when working in Interface Builder. It effectively gets "converted" to a multiplier.

You can confirm this while debugging by inspecting the constraint's .multiplier property. If you set a view's width to 60, and multiplier to 1:2 (resulting in an auto-layout height of 120), the actual value of .multiplier will be 0.5.

So, in my view, it depends on what feels more natural.

If I want a view to be 90% of the width of another view, I am much more likely to set the Multiplier to 0.9 --- which gives the exact same result as setting it to 9:10.

However, if I want a view to maintain an aspect ration of, say, 3-to-2, I am much more likely to set the Multiplier to 3:2 rather than 1.5.

Using a ratio can also be convenient when you have "non-simple" values. That is, it's easy to understand that a ratio of 3:2 is the same as 1.5. But what if I have an image with native size of 281 x 60, and I want to use those values to maintain ratio? 281:60 is easier to understand than .multiplier = 4.68333339691162.

And, while they are interchangeable, it is probably a bit more intuitive to use Ratio when constraining an object to itself - e.g. I want my view's width to be 2 x its own height, so 2:1 - and using Multiplier when constraining one object to another - e.g. I want my view's width to be 75% of the width of its superview, so 0.75.

### Difference between nil, NIL and null

Ans :

The difference is that while
NULL represents zero for any pointer,
nil is specific to objects (e.g., id) and
Nil is specific to class pointers.

Nil,Null and nil are used with below
1> Nil for Objective c Class
2> nil for Objective c object
3> Null for C pointer
Example:
1>Class A=Nil;
2>NSString strName=nil;
3>char *pointerChar = NULL;