Problem
Given a text file file.txt, transpose its content.
You may assume that each row has the same number of columns and each field is separated by the ' ' character.
Example:
If file.txt has the following content:
1 | |
Output the following:
1 | |
Given a text file file.txt, transpose its content.
You may assume that each row has the same number of columns and each field is separated by the ' ' character.
Example:
If file.txt has the following content:
1 | |
Output the following:
1 | |
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.
You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)
You may also assume each line in the text file must not contain leading or trailing white spaces.
Example:
Assume that file.txt has the following content:
1 | |
Your script should output the following valid phone numbers:
1 | |
Write a bash script to calculate the frequency of each word in a text file words.txt.
For simplicity sake, you may assume:
words.txt contains only lowercase characters and space ' ' characters.Example:
Assume that words.txt has the following content:
1 | |
Your script should output the following, sorted by descending frequency:
1 | |
Note:
Write a function that takes an unsigned integer and return the number of ‘1’ bits it has (also known as the Hamming weight).
Example 1:
1 | |
Example 2:
1 | |
Example 3:
1 | |
Note:
-3.Follow up:
If this function is called many times, how would you optimize it?
Reverse bits of a given 32 bits unsigned integer.
Example 1:
1 | |
Example 2:
1 | |
Note:
-1073741825.Follow up:
If this function is called many times, how would you optimize it?
Given an array, rotate the array to the right by k steps, where k is non-negative.
Example 1:
1 | |
Example 2:
1 | |
Note:
Say you have an array for which the i-th element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most k transactions.
Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
Example 1:
1 | |
Example 2:
1 | |
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
Example:
1 | |
Given an input string , reverse the string word by word.
Example:
1 | |
Note:
Follow up: Could you do it in-place without allocating extra space?
The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id.
1 | |
The Department table holds all departments of the company.
1 | |
Write a SQL query to find employees who earn the top three salaries in each of the department. For the above tables, your SQL query should return the following rows (order of rows does not matter).
1 | |
Explanation:
In IT department, Max earns the highest salary, both Randy and Joe earn the second highest salary, and Will earns the third highest salary. There are only two employees in the Sales department, Henry earns the highest salary while Sam earns the second highest salary.