码迷,mamicode.com
首页 > 其他好文 > 详细

Facebook 电面 02/01 2018

时间:2018-02-02 11:30:51      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:max   exe   include   vector   end   shared   gpo   view   product   

/*Welcome to Facebook!

This is just a simple shared plaintext pad, with no execution capabilities.

When you know what language you‘d like to use for your interview,
simply choose it from the dropdown in the top bar.

Enjoy your interview!

hello!

 1 2 3 5 2 4 6 -> 4*/
 
#include <vector>
#include <iostream>
  
int findLongestContinousSequence(vector<int>&nums)
{
  if(nums.size()) return 0;
  int cnt = 1;
  int max_cnt = 1;
  for(int i = 1;i<nums.size();i++)
  {
    if(nums[i]>=nums[i-1]) cnt++;
    else cnt= 1;
    max_cnt = max(max_cnt,cnt);
  }
  return max_cnt;
}


dp[i] = dp[j]+1;//for j between [0,i] if nums[i]>nums[j];


int main()
{
  vector<int> nums = {7,3,5,8,9,2,3,10};
  int cnt = findLongestContinousSequence(nums);
  cout << cnt << endl;
}

dot product

v1 = [1, 0, 1]
v2 = [1, 1, 1]

v1 dp v2 = 1 + 0 + 1= 2

struct node
{
  int idx
  int val;
  node(int _idx,int _val)
  {
    idx = _idx;
    val = _val;
  }
}
  
bool get_data(vector<node>&data1,vector<node>&data2)
  

class dotProduct
{
     int dot_product()
     {
        vector<node> dat1,dat2;
        int sum = 0;
        get_data(dat1,dat2)
        
        int idx1 = 0,idx2 = 0;
        // O(min(dat1.size(),dat2.size())
        while(idx1<dat1.size() && idx2<dat2.size())
        {
           if(dat1[idx1].idx == dat2[idx2].idx) sum += dat1[idx1].val*dat2[idx2].val;
           else if (dat1[idx1].idx == dat2[idx2].idx) idx1++;
           else idx2++;
        }               
       return sum;
     }
}
  

 

Facebook 电面 02/01 2018

标签:max   exe   include   vector   end   shared   gpo   view   product   

原文地址:https://www.cnblogs.com/jxr041100/p/8403329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!