This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger) findHammingDistance: (NSInteger)one : (NSInteger)two { | |
NSInteger count = 0; | |
NSInteger xor = one ^ two; | |
while (xor) { | |
count += (xor & 1); | |
xor = xor >> 1; | |
} | |
return count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(BOOL) HasRobotReturnedToOrigin : (NSString *) path | |
{ | |
NSInteger i = 0; | |
NSInteger verticalCounter = 0; | |
NSInteger horizontalCounter = 0; | |
while (i < path.length) | |
{ | |
if ([[path substringWithRange:NSMakeRange(i, 1)] isEqualToString:@"U"]) | |
{ | |
verticalCounter++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Method 1 | |
-(NSArray *) sortArrayByParityIIMethodOne : (NSMutableArray *) arr | |
{ | |
NSString* temp; | |
NSInteger oddIndex = 1; | |
for (NSInteger i = 0; i < arr.count ; i=i+2) | |
{ | |
temp = [arr objectAtIndex:i]; | |
// If index is even and value not even : | |
if (i % 2 == 0 && [arr[i]intValue] % 2 != 0){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSInteger) PeakIndex : (NSArray *) A | |
{ | |
for (NSInteger i = 1 ; i < A.count-1 ; i++) | |
{ | |
if (([A objectAtIndex:i-1] < [A objectAtIndex:i]) | |
&& ([A objectAtIndex:i+1] < [A objectAtIndex:i])) | |
{ | |
return i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString *) ToLowerCase : (NSMutableString *) inputString | |
{ | |
NSInteger i = 0; | |
while (i < inputString.length) | |
{ | |
int character = [inputString characterAtIndex:i]; | |
if (character < 97) | |
{ | |
[inputString replaceCharactersInRange:NSMakeRange(i, 1) | |
withString:[NSString stringWithFormat:@"%c",character+32]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger) jewelCountFromStone : (NSString*) stone : (NSString*) jewel | |
{ | |
NSInteger count = 0; | |
NSMutableDictionary *hashmap = [[NSMutableDictionary alloc]initWithCapacity:jewel.length]; | |
for ( NSInteger i = 0; i< jewel.length; i++) | |
{ | |
[hashmap setValue:[NSNumber numberWithInteger:1] forKey: [jewel substringWithRange:NSMakeRange(i,1)]]; | |
} | |
for ( NSInteger i = 0 ; i <stone.length ; i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray *) anagramMapping :(NSMutableArray *) a : (NSMutableArray *) b | |
{ | |
NSMutableArray *output = [[NSMutableArray alloc]initWithCapacity:a.count]; | |
NSMutableDictionary *hashtable = [[NSMutableDictionary alloc]init]; | |
for (NSInteger i = 0; i < b.count ;i++) | |
{ | |
[hashtable setObject:[NSNumber numberWithInteger:i] forKey:[b[i] stringValue]]; | |
} | |
for (NSInteger i = 0; i < a.count ;i++) |