Tag: cha

How to Change the Computer Name in Ubuntu

1. Open a terminal window. 2. At the input prompt you will see this structure: “` nicholas@computer-name:~$ _ “` 3. So you have to edit the hostname file: “` sudo nano /etc/hostname “` 4. When prompted, enter the administrator password and hit Enter. 5. The hostname file will open, showing the current computer name. Replace the…

Awesome New Layout!

Well, it is always good to have a refreshing layout. I spent like 2 days to tweak my website layout. It’s really awesome. Useless widgets are removed and background changed. There is even a whole new typography. I love it so much!

Interview Practice Extra 06 – Vending Machine

Question This is an actual question I encountered in an Amazon phone interview in November 2013. You are going to design the money changing algorithm for a vending machine. That is, after any purchase, the machine makes change to users with a combination of coins. And the machine only have 3 types of coins: nickel…

Interview Practice 26 – String Right-rotation

Question Write a program to right-rotate a string by m characters. Right-rotating a string means moving m characters at the left of string to the right. Is it required the time complexity is O(n) and helper memory size is O(1). For example, right-rotate “abcdefghi” by 3 characters gives “defghiabc”. Solution There are 2 ways to…

Interview Practice 25 – Longest Consecutive Digits

Question Given a function prototype: int continumax(char *output_string,char *input_string). Implement it to find the longest consecutive digits. This function must return the length of the longest digits. The found longest digits should be written to the memory location that output_string is pointing. For example, if input_string is “abcd12345ed125ss123456789”, function returns 9 and output_string becomes “123456789”. Solution This…

Interview Practice 20 – Convert String to Integer

Question Convert the inputted string to an integer. For example, “345” will output 345. Solution Though it looks simple, in fact it is pretty tricky. First we need to make the concept clear. 1. Scan each character from the left to right, then multiply the previously obtained integer by ten before adding the scanned digit…

Interview Practice 17 – Find The String Appeared Once

Question Given a string, write an algorithm to find the character inside that appeared only once. For example, the result for string “abaccdeff” is b. Solution We can use a hashtable to count the appearance times for each character. Then rescan the hashtable for the character that appeared only once. These two step take O(n)…

Interview Practice 13 – Last Kth Node of Linked List

Question Given a linked list, find the Kth last node in a linked list. The last 0th node is the tail node in the linked list. Solution Easy task. Construct 2 pointers: P1 and P2. First, both of them are set to head. Move P2 to the next Kth node. Example # node structure class…