注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
上一篇误点击发送。。。不知道能不能删除啊。
题主是四月10号被recruiter在LinkedIn上联系才申请的。然后申请完立马给了oa,但一直拖着没有做,期间recruiter催了一次。我昨天刚刚做完
以下是悉尼的试题(附代码):
1. Simple Max Difference:
Given an array arr[] of integers, find out the maximum difference between any two elements such that larger element appears after the smaller number.
Input : arr = {2, 3, 10, 6, 4, 8, 1}
Output : 8
Explanation : The maximum difference is between 10 and 2.
Input : arr = {7, 9, 5, 6, 3, 2}
Output : 2
Explanation : The maximum difference is between 9 and 7.
- def maxDiff(arr):
- max_diff = arr[1] - arr[0]
- min_element = arr[0]
-
- for i in range( 1, len(arr)):
- if (arr[i] - min_element > max_diff):
- max_diff = arr[i] - min_element
-
- if (arr[i] < min_element):
- min_element = arr[i]
- return max_diff
-
复制代码
2. bouquets of Flowers:
Lara owns a flower shop, where she sells only two types of flower bouquets:
Type 1: The first type of bouquet contains three roses and costs p dollars.
Type 2: The second type of bouquet contains one cosmos and one rose and costs q dollars.
Lara grows these flowers in her own garden in a single row. You can consider the row as a one-dimensional array where each cell either contains a rose or a cosmos. For example array 001101011, here 0 indicates rose and 1 indicates cosmos.
There is an important rule that Lara follows when she makes the bouquets: she makes each bouquet with only consecutive flowers from the array. For example, in a bouquet, the flower from consecutive indices (i, i+1, and i+2) in the array can be present, but not from non-consecutive indices (i and i+2). In the array above, Lara can’t make any bouquets of type 1 but she can make 3 bouquets of type 2.
Now she wonders what is the maximum profit she can make if she makes these bouquets optimally. You are given a binary string representing her garden row. Calculate the maximum profit Lara can make. Remember it’s not necessary to use all the flowers.
Function Description
Complete the flowerBouquets function in the editor below. The function must return an integer denoting the maximum profit Lara can make if she makes her bouquets optimally.
3. longest chain:
Given an array, words, of n word strings (words[0], words[1],..., words[n-1]), choose a word from it and, in each step, remove a single letter from the chosen word if and only if doing so yields another word that is already in the library. Each successive character removal should be performed on the result of the previous removal, and you cannot remove a character if the resulting string is not an element in words(see Explanation below for detail). The length of a string chain is the maximum number of strings in a chain of successive character removals.
Complete the longestChain function in your editor. It has 1 parameter: an array of n strings, words, where the value of each element words; (where 0 <= i < n) is a word. It must return single integer denoting the length of the longest possible string chain in words.
Input Format
The locked stub code in your editor reads the following input from stdin and passes it to your function: The fist line contains an integer. n, the size of the words array. Each line i of the n subsequent lines (where 0 <= i < n) contains an integer describing the respective strings in words.
Constraints
1 <= n <= 50000
1 <= |words_i| <= 50, where 0 <= i < n
Each string in words is composed of lowercase ASCII letters.
Output Format
Your function must return a single integer denoting the length of the longest chain of character removals possible.
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.HashSet;
- public class LongestChain {
- public static void main(String[] args) {
- String[] words = {
- "a",
- "b",
- "ba",
- "bca",
- "bda",
- "bdca"
- };
- System.out.println("Longest Chain Length : " + longest_chain(words));
- }
- static int longest_chain(String[] w) {
- if (null == w || w.length < 1) {
- return 0;
- }
- int maxChainLen = 0;
- HashSet<String> words = new HashSet<>(Arrays.asList(w));
- HashMap<String, Integer> wordToLongestChain = new HashMap<>();
- for (String word : w) {
- if (maxChainLen > word.length()) {
- continue;
- }
- int curChainLen = find_chain_len(word, words, wordToLongestChain) + 1;
- wordToLongestChain.put(word, curChainLen);
- maxChainLen = Math.max(maxChainLen, curChainLen);
- }
- return maxChainLen;
- }
- static int find_chain_len(String word, HashSet<String> words, HashMap<String, Integer> wordToLongestChain) {
- int curChainLen = 0;
- for (int i = 0; i < word.length(); i++) {
- String nextWord = word.substring(0, i) + word.substring(i + 1);
- if (words.contains(nextWord)) {
- if (wordToLongestChain.containsKey(nextWord)) {
- curChainLen = Math.max(curChainLen, wordToLongestChain.get(nextWord));
- } else {
- int nextWordChainLen = find_chain_len(nextWord, words, wordToLongestChain);
- curChainLen = Math.max(curChainLen, nextWordChainLen + 1);
- }
- }
- }
- return curChainLen;
- }
- }
复制代码
4.Fun with Anagram:
Given a list of words, if there's anagram of such word coming afterwards, delete them:
Sample: [Code, cdoe, deoc, framer, frame] ==> [code, framer, frame]
- def anagram( s, t):
- # write your code here
- # write your code here
- set_s = [0] * 256
- set_t = [0] * 256
- for i in range(0, len(s)):
- set_s[ord(s[i])] += 1
- for i in range(0, len(t)):
- set_t[ord(t[i])] += 1
- for i in range(0, 256):
- if set_s[i] != set_t[i]:
- return False
- return True
- def funWithAnagram(list):
- res = []
- anagram = False
- for word in list:
- for element in res:
- if anagram(element, word):
- anagram = True
- break
- if Anagram = False:
- res.append(word)
- else:
- anagram = True
- return res
复制代码
5. Initial Public Offering
挺简单的没截图。
加个米呗 谢谢
|