Saturday, November 15, 2014

Converting 2D NxN Array into a List in Spiral Order

Given a 2D NxN array. Print the array into a lost in spiral order.

Example:
If the input array if the following:
00     01     02     03
10     11     12     13
20     21     22     23
30     31     32     33
Then the output will be:
00     01     02     03     13     23     33     32     31     30     20     10     11     12     22     21

The following is a program using Java.

public ArrayList<Character> getSpiralArrayList(char[][] input) {
int size = input.length;
ArrayList<Character> output = new ArrayList<Character>();
if(input[0].length != size) {
System.out.println("Error: Not a NxN Matrix");
return output;
} else {
int top, bottom, left, right;
top = left = 0;
bottom = right = size-1;
for(int layer=0;layer<(size-1); layer++) {
for(int row=left;row<=right;row++)
output.add(input[top][row]);
top++;
for(int column=top; column<=bottom; column++)
output.add(input[column][right]);
right--;
for(int row=right; row>=left; row--)
output.add(input[bottom][row]);
bottom--;
for(int column=bottom; column>=top; column--)
output.add(input[column][left]);
left++;
}
return output;
}
}

Example input = {{'q','w','e'},{'r','t','y'},{'u','i','o'}};

Wednesday, November 5, 2014

App Store: Installing Older Versions of Apps

I got an iPod Touch 4th Generation from my uncle. He was using it for few years and before I got it. It was made to factory reset and hence it got erased all data and app from the device.

I created a new icloud account and started to configure it.

It had iOS 6 preinstalled in it. But current version of iOS is 8. Many apps like Facebook, Skype which we use daily supports only iOS 7 and above.

The App Store contained only latest apps and hence whenever I try to install, it throwed an error,
"This application requires iOS 7.0 or later" - Dismiss

I tried several times and asked few friends but nothing worked out. I found something here: http://support.apple.com/en-us/ht5919 but that too did not work. I went to my Purchased screen and found it empty. There was nowhere I was not able to find the option which provides a download. Some friends even suggested for jail breaking which I wasn't willing to.

Then I tried this which worked.
Just Follow the steps:
  1. I had a Windows 8.1 PC. I installed iTunes there and logedin using my newly created account. In that there is an App Store where I downloaded these apps. 
  2. As soon as I download these apps using WinPC iTunes, I can see the apps are showing in my iPod Purchase Screen. 
  3. The Purchase Screen is in the updates area of the App Store in iOS. 
  4. Go there and download the app again, it will download and install. Now you can follow this link: http://support.apple.com/en-us/ht5919 Everything will come to place
UA-39217154-2