楼主: fish444555
跳转到指定楼层
上一主题 下一主题
收起左侧

Akuna Capital OA

🔗
huai10 2016-8-22 23:46:36 | 只看该作者
全局:
楼主第四题有啥想法么
回复

使用道具 举报

🔗
 楼主| fish444555 2016-8-23 06:36:27 | 只看该作者
全局:
huai10 发表于 2016-8-22 23:46
楼主第四题有啥想法么
  1. class tt {

  2.         /**
  3.          * @param args
  4.          */
  5.         public static void main(String[] args) {
  6.                 // TODO Auto-generated method stub
  7.                 int[] nums1 = { 8, 9, 10, 1, 2, 3, 4};
  8.                 int[] nums2 = { 8, 9, 10, 1, 2, 3};
  9.                 int[] nums3 = { 10, 9, 2, 5, 3, 7};
  10.                 Solution tt = new Solution();
  11.                 List<Integer> res = tt.LongestSortedSubrange(nums1, 3);
  12.                 for (int j = 0; j < res.size(); j++) {
  13.                         System.out.print(res.get(j) + "\t");
  14.                 }
  15.                 System.out.println();
  16.                 res = tt.LongestSortedSubrange(nums2, 3);
  17.                 for (int j = 0; j < res.size(); j++) {
  18.                         System.out.print(res.get(j) + "\t");
  19.                 }
  20.                 System.out.println();
  21.                 res = tt.LongestSortedSubrange(nums3, 3);
  22.                 for (int j = 0; j < res.size(); j++) {
  23.                         System.out.print(res.get(j) + "\t");
  24.                 }
  25.         }
  26. }



  27. class Solution {
  28.     public List<Integer> LongestSortedSubrange(int[] nums, int m) {
  29.         List<Integer> res = new ArrayList<Integer>();
  30.         if (nums == null || nums.length == 0) {
  31.             return res;
  32.         }
  33.         //record every element idx
  34.         Map<Integer, Integer> map = new HashMap<>();
  35.                 for (int i = 0; i < nums.length; i++) {
  36.             map.put(nums[i], i);
  37.         }
  38.         Arrays.sort(nums);
  39.         dfs(nums, m, res, new ArrayList<Integer>(), nums.length - 1, map);
  40.         return res;
  41.     }

  42.     private void dfs(int[] nums, int m, List<Integer> res, List<Integer> cur, int pos, Map<Integer, Integer> map) {
  43.             // get the longest one
  44.         if (pos < 0 && m >= nums.length - cur.size() && cur.size() > res.size()) {
  45.                 res.clear();
  46.                 res.addAll(cur);
  47.             return;
  48.         }
  49.         // get the biggest summation
  50.         if (pos < 0 && m >= nums.length - cur.size() && cur.size() == res.size()) {
  51.             int resSum = 0, curSum = 0;
  52.             for (int i = 0; i < cur.size(); i++) {
  53.                 resSum += res.get(i);
  54.                 curSum += cur.get(i);
  55.             }
  56.             if (curSum > resSum) {
  57.                     res.clear();
  58.                     res.addAll(cur);
  59.             }
  60.             return;
  61.         }
  62.         for (int i = pos; i >= 0; i--) {     
  63.                 //begin from last one, find the longest sub-sequence
  64.                 if (cur.isEmpty()) {
  65.                         cur.add(nums[i]);
  66.                         dfs(nums, m, res, cur, i - 1, map);
  67.                         cur.remove(0);
  68.                 }
  69.                 //the idx of i_th element greater than the idx of 0 element of cur
  70.                 //cannot contruct a increasing sub-sequence
  71.                 else if (map.get(nums[i]) > map.get(cur.get(0))) {
  72.                         if (i == 0) {
  73.                                 dfs(nums, m, res, cur, i - 1, map);
  74.                 }
  75.             }
  76.             else {
  77.                 cur.add(0, nums[i]);
  78.                 dfs(nums, m, res, cur, i - 1, map);
  79.                 cur.remove(0);
  80.             }
  81.         }
  82.     }
  83. }
复制代码
不确定是否正确,只测试了简单的例子

int[] nums1 = { 8, 9, 10, 1, 2, 3, 4};

tt.LongestSortedSubrange(nums1, 3);
1        2        3        4       

int[] nums2 = { 8, 9, 10, 1, 2, 3};
res = tt.LongestSortedSubrange(nums2, 3);
8        9        10       

int[] nums3 = { 10, 9, 2, 5, 3, 7};
res = tt.LongestSortedSubrange(nums3, 3);
2        5        7

有什么想法大家讨论一下
回复

使用道具 举报

🔗
 楼主| fish444555 2016-8-23 08:24:05 | 只看该作者
全局:
fish444555 发表于 2016-8-23 06:36
不确定是否正确,只测试了简单的例子

int[] nums1 = { 8, 9, 10, 1, 2, 3, 4};

之前想复杂了,而且排序,应该不需要, 测试例子和输出一样
  1. class tt {

  2.         /**
  3.          * @param args
  4.          */
  5.         public static void main(String[] args) {
  6.                 // TODO Auto-generated method stub
  7.                 int[] nums1 = { 8, 9, 10, 1, 2, 3, 4};
  8.                 int[] nums2 = { 8, 9, 10, 1, 2, 3};
  9.                 int[] nums3 = { 10, 9, 2, 5, 3, 7};
  10.                 Solution tt = new Solution();
  11.                 List<Integer> res = tt.LongestSortedSubrange(nums1, 3);
  12.                 for (int j = 0; j < res.size(); j++) {
  13.                         System.out.print(res.get(j) + "\t");
  14.                 }
  15.                 System.out.println();
  16.                 res = tt.LongestSortedSubrange(nums2, 3);
  17.                 for (int j = 0; j < res.size(); j++) {
  18.                         System.out.print(res.get(j) + "\t");
  19.                 }
  20.                 System.out.println();
  21.                 res = tt.LongestSortedSubrange(nums3, 3);
  22.                 for (int j = 0; j < res.size(); j++) {
  23.                         System.out.print(res.get(j) + "\t");
  24.                 }
  25.         }
  26. }



  27. class Solution {
  28.     public List<Integer> LongestSortedSubrange(int[] nums, int m) {
  29.         List<Integer> res = new ArrayList<Integer>();
  30.         if (nums == null || nums.length == 0) {
  31.             return res;
  32.         }
  33.         dfs(nums, m, res, new ArrayList<Integer>(), 0);
  34.         return res;
  35.     }

  36.     private void dfs(int[] nums, int m, List<Integer> res, List<Integer> cur, int pos) {
  37.             // get the longest one
  38.         if (m >= nums.length - cur.size() && cur.size() > res.size()) {
  39.                 res.clear();
  40.                 res.addAll(cur);
  41.             return;
  42.         }
  43.         // get the biggest summation
  44.         if (m >= nums.length - cur.size() && cur.size() == res.size()) {
  45.             int resSum = 0, curSum = 0;
  46.             for (int i = 0; i < cur.size(); i++) {
  47.                 resSum += res.get(i);
  48.                 curSum += cur.get(i);
  49.             }
  50.             if (curSum > resSum) {
  51.                     res.clear();
  52.                     res.addAll(cur);
  53.             }
  54.             return;
  55.         }
  56.         for (int i = pos; i < nums.length; i++) {     
  57.                 if (cur.isEmpty()) {
  58.                         cur.add(nums[i]);
  59.                         dfs(nums, m, res, cur, i + 1);
  60.                         cur.remove(cur.size() - 1);
  61.                 }
  62.                 else if (nums[i] > cur.get(cur.size() - 1)) {
  63.                 cur.add(nums[i]);
  64.                 dfs(nums, m, res, cur, i + 1);
  65.                 cur.remove(cur.size() - 1);
  66.             }
  67.         }
  68.     }
  69. }
复制代码
回复

使用道具 举报

🔗
Augustus 2016-8-24 12:39:17 | 只看该作者
全局:
楼主能不能说下第五题?基本没看懂说的是什么。。。
回复

使用道具 举报

🔗
 楼主| fish444555 2016-8-24 21:47:38 | 只看该作者
全局:
Augustus 发表于 2016-8-24 12:39
楼主能不能说下第五题?基本没看懂说的是什么。。。

Problem 5

Word Distance

Given a sequence of words, construct an algorithm that returns the number of times word x appears within n words of word y.


上面是原题题目,我一开始也不太懂,后来看测试例子才大概了解, 下面是测试例子的输入,输出的话忘记记录了,我觉得大概意思就是x, y 间隔 n 个单词,符合这个条件的次数是多少

case 1:
Input
"I cannot simply cannot believe I ate the whole thing", "I", "cannot", 2

Output
2

Input
case 2: "big red fish small blue fish one big fish two big fish big shark", "fish", "big", 1

Output
3

Input
"up up down down left right left right b a b a select start", "down", "right", 2

Output
1
回复

使用道具 举报

🔗
liguanzhu92 2016-8-25 13:14:55 | 只看该作者
全局:
求问楼主申请的是jr developer#几?我收到了#2和#4两个欸!!!。。。都是90miin。。。。
回复

使用道具 举报

🔗
huai10 2016-8-25 13:48:05 | 只看该作者
全局:
liguanzhu92 发表于 2016-8-25 13:14
求问楼主申请的是jr developer#几?我收到了#2和#4两个欸!!!。。。都是90miin。。。。

求你们做完发面经
回复

使用道具 举报

🔗
 楼主| fish444555 2016-8-25 20:56:09 | 只看该作者
全局:
liguanzhu92 发表于 2016-8-25 13:14
求问楼主申请的是jr developer#几?我收到了#2和#4两个欸!!!。。。都是90miin。。。。

Jr Dev #1
字数字数字数
回复

使用道具 举报

🔗
Daraxu 2016-8-25 21:38:39 | 只看该作者
全局:
未开始申请的小白求科普 什么是OA啊 还有看到地里很多人说onsite 这些是什么意思呢 求前辈们科普 感激!
回复

使用道具 举报

🔗
 楼主| fish444555 2016-8-25 21:58:07 | 只看该作者
全局:
Daraxu 发表于 2016-8-25 21:38
未开始申请的小白求科普 什么是OA啊 还有看到地里很多人说onsite 这些是什么意思呢 求前辈们科普 感激!

OA, 就是电话面试之前做的编程测试之类的,可能也有选择题,问答题,onsite 就是去公司面对面面试之类的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表