📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 16
跳转到指定楼层
上一主题 下一主题
收起左侧

Headlands OA

全局:

2023(1-3月) 码农类General 博士 全职@headlands - 猎头 - 在线笔试  | 😐 Neutral 😐 Average | Other | 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
OA题目同, 万年不变。

他只有两个test case,所以我也不知道我写
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
12 +8:00):
补充:没过。

评分

参与人数 2大米 +5 收起 理由
匿名用户-IGGK3 + 4
bieguanwoshishe + 1 很有用的信息!

查看全部评分


上一篇:2023亚麻Research Scientist Intern
下一篇:热乎的walleye店面
推荐
RedAlice 2023-5-19 04:26:09 | 只看该作者
全局:
我三月份电面就挂了经历相似 把我过的CODE po下吧
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4. #include <list>
  5. #include <set>
  6. #include <cstring>
  7. #include <bits/stdc++.h>  

  8. using namespace std;


  9. bool VerifyAndSplitHeader(const string& column, vector<string>& column_titles) {
  10.     if (column.empty()) return false;
  11.     if (column[0] != '#') return false;
  12.     stringstream ss(column.substr(1));
  13.     for (int i = 0;i < 3; i++) {
  14.         if (!getline(ss, column_titles[i], ',')) return false;
  15.     }
  16.     if (!ss.eof()) return false;

  17.     set<string> column_mandate = {"job_id","runtime_in_seconds","next_job_id"};
  18.     set<string> column_input_set(column_titles.begin(), column_titles.end());

  19.     if (column_mandate != column_input_set) return false;

  20.     return true;
  21. }

  22. bool VerifyAndSplitLine(const string& line, vector<int>& inputs) {
  23.     if (line.empty()) return false;
  24.     stringstream ss(line);
  25.     for (int i = 0;i < 3; i++) {
  26.         string buf;
  27.         if (!getline(ss, buf, ',')) return false;
  28.         stringstream sstoi(buf);
  29.         sstoi >> inputs[i];
  30.         if (sstoi.fail() || !sstoi.eof()) return false;
  31.     }
  32.     if (!ss.eof()) return false;

  33.     return true;
  34. }

  35. string HHMMSS(int seconds) {
  36.     stringstream ss;
  37.     int hour = seconds / 3600;
  38.     int min = seconds % 3600 / 60;
  39.     int secon = seconds % 60;

  40.     ss << setw(2) << setfill('0') << hour << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << setfill('0') << secon;
  41.     string result;
  42.     ss >> result;
  43.     return result;
  44. }

  45. void OutputChain(vector<int> chain) {
  46.     cout << "-" << endl;
  47.     cout << "start_job: " << chain[0] << endl;
  48.     cout << "last_job: " << chain[1] << endl;
  49.     cout << "number_of_jobs: " << chain[2] << endl;
  50.     cout << "job_chain_runtime: " << HHMMSS(chain[3]) << endl;
  51.     cout << "average_job_time: " << HHMMSS(chain[4]) << endl;
  52. }

  53. void PrintChains(list<list<pair<int, int>>> chains) {
  54.     for (const auto& chain : chains) {
  55.             cout << endl;
  56.             for (const auto& job : chain) {
  57.                 cout << "job_id: " << job.first << " time: " << job.second << endl;
  58.             }
  59.             cout << "chain over" << endl;
  60.             }
  61.         cout << endl;
  62. }

  63. int main() {
  64.     vector<string> column_titles(3, "");
  65.     string column_buffer;
  66.     cin >> column_buffer;
  67.     if (cin.fail()) { cout <<  "Malformed Input" << endl; return 0; }
  68.    
  69.     if (!VerifyAndSplitHeader(column_buffer, column_titles)) { cout <<  "Malformed Input" << endl; return 0; };

  70.     int job_id_column, runtime_column, next_job_id_column;

  71.     for (int i = 0; i < 3; i++) {
  72.         if (column_titles[i] == "job_id") job_id_column = i;
  73.         else if (column_titles[i] == "runtime_in_seconds") runtime_column = i;
  74.         else next_job_id_column = i;
  75.     }

  76.     list<list<pair<int, int>>> chains;
  77.     unordered_map<int, list<list<pair<int, int>>>::iterator> jobs;
  78.     unordered_map<int, int> insert_pos;
  79.     vector<int> opens;
  80.     while (!cin.eof()) {
  81.         vector<int> input(3, 0);
  82.         string line;
  83.         cin >> line;
  84.         cout << "line size:" << line.size() << endl;
  85.         if (cin.fail()) break;
  86.         if (!VerifyAndSplitLine(line, input)) { cout <<  "Malformed Input" << endl; return 0; }

  87.         int job_id = input[job_id_column];
  88.         int runtime_in_seconds = input[runtime_column];
  89.         int next_job_id = input[next_job_id_column];

  90.         if (runtime_in_seconds < 0 || job_id == next_job_id) { cout <<  "Malformed Input" << endl; return 0; }

  91.         if (jobs.find(job_id) != jobs.end()) {cout <<  "Malformed Input" << endl; return 0;} // No duplicate jobs ... 1
  92.         if (insert_pos.find(next_job_id) != insert_pos.end()) {cout <<  "Malformed Input" << endl; return 0;} // No duplicate next job pointers: current input cannot have the same next job as existing jobs ... 2
  93.    
  94.         if (insert_pos.find(job_id) != insert_pos.end()) { // If the input has pre
  95.             cout << job_id << " has Pre: " << insert_pos[job_id] << endl;
  96.             int pre = insert_pos[job_id];
  97.             if (jobs.find(next_job_id) != jobs.end()) { // If current job has next and next is already seen
  98.                 if (jobs[pre]->begin() == jobs[next_job_id]->begin()) { // should not point to the head of its pre
  99.                     cout << "Malformed Input" << endl;
  100.                     return 0;
  101.                 }
  102.             }
  103.             // put into someone's next here first, worry about having next later
  104.             cout << "before push to back" << endl;
  105.             PrintChains(chains);
  106.             jobs[job_id] = jobs[pre];
  107.             jobs[job_id]->push_back({job_id, runtime_in_seconds});

  108.             cout << "after push to back" << endl;
  109.             PrintChains(chains);

  110.             cout << "Pushing to back job_id: " << job_id << " runtime: " << runtime_in_seconds << endl;
  111.             
  112.         }

  113.         if (next_job_id != 0) { // if current job has next, try to either:
  114.             cout << job_id << " record Next: " << next_job_id << endl;
  115.             opens.push_back(next_job_id);
  116.             insert_pos[next_job_id] = job_id;
  117.             if (insert_pos.find(job_id) == insert_pos.end()) { // insert at the beginning of an existing list or create a new list.
  118.                 if (jobs.find(next_job_id) != jobs.end()) {
  119.                     cout << "before push to front" << endl;
  120.                     PrintChains(chains);
  121.                     jobs[next_job_id]->push_front({job_id, runtime_in_seconds});
  122.                     jobs[job_id] = jobs[next_job_id];

  123.                     cout << "after push to front" << endl;
  124.                     PrintChains(chains);

  125.                 } else {
  126.                     cout << job_id << " no existing Next: " << next_job_id << endl;
  127.                     cout << "before new list" << endl;
  128.                     PrintChains(chains);
  129.                     chains.push_back(list<pair<int,int>>());
  130.                     chains.back().push_back({job_id, runtime_in_seconds});
  131.                     jobs[job_id] = chains.end();
  132.                     jobs[job_id]--;
  133.                     cout << "after new list" << endl;
  134.                     PrintChains(chains);
  135.                 }
  136.             } else if (jobs.find(next_job_id) != jobs.end()) {  // it has pre so it is already installed, if existing next move the existing list to after
  137.                 auto remove = jobs[next_job_id];
  138.                 cout << "will remove: " << next_job_id << endl;
  139.                 cout << "before combine" << endl;
  140.                 PrintChains(chains);
  141.                 for (auto job : *remove) {
  142.                     jobs[job_id]->push_back(job);
  143.                     jobs[job.first] = jobs[job_id];
  144.                 }
  145.                 chains.erase(remove);
  146.                 cout << "after combine" << endl;
  147.                 PrintChains(chains);
  148.             }
  149.             
  150.         } else if (insert_pos.find(job_id) == insert_pos.end()) { // No existing pre, no next ever.
  151.             cout << "before single chain" << endl;
  152.             PrintChains(chains);
  153.             chains.push_back(list<pair<int,int>>());
  154.             chains.back().push_back({job_id, runtime_in_seconds});
  155.             jobs[job_id] = chains.end();
  156.             jobs[job_id]--;
  157.             cout << "after single chain" << endl;
  158.             PrintChains(chains);
  159.         }
  160.     }

  161.     for (const auto& open : opens) {
  162.         if (jobs.find(open) == jobs.end()) { cout <<  "Malformed Input" << endl; return 0; }
  163.     }

  164.     vector<pair<int, vector<int>>> sort_output;

  165.     for (const auto& chain : chains) {
  166.         int total_runtime = 0;
  167.         for (const auto& job : chain) {
  168.             total_runtime += job.second;
  169.             if (total_runtime > 86400) { cout <<  "Malformed Input" << endl; return 0; }
  170.         }
  171.         sort_output.push_back({total_runtime, {
  172.             chain.front().first,
  173.             chain.back().first,
  174.             chain.size(),
  175.             total_runtime,
  176.             total_runtime / chain.size()
  177.         }});
  178.     }

  179.     sort(sort_output.rbegin(), sort_output.rend());

  180.     for (const auto& output : sort_output) {
  181.         OutputChain(output.second);
  182.     }

  183.     if (!chains.empty()) cout << "-" << endl;
  184.    

  185.     return 0;
  186. }
复制代码
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-PMG6G  2024-10-18 03:18:04
120分钟 zszszs
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-S76IU  2023-4-2 07:24:49
经常看到楼主最近发的面经,可以请教楼主都是怎么投的这些公司呀(海投/refer?)以及怎么找到这些还在招人的公司呢?
回复

使用道具 举报

🔗
 楼主| Heinrich 2023-4-2 07:31:39 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
 楼主| Heinrich 2023-4-8 13:58:27 | 只看该作者
全局:
把我当时自己的代码贴上来,注意,没过哈。
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <unordered_map>
  6. #include <unordered_set>
  7. #include <set>
  8. #include <vector>

  9. using namespace std;

  10. namespace Solution {

  11. bool IsPositiveNumber(const std::string& s) {
  12.   if (s.empty()) {
  13.     return false;
  14.   }
  15.   for (const char& c : s) {
  16.     if (c != ' ' && !isdigit(c)) {
  17.       return false;
  18.     }
  19.   }
  20.   return true;
  21. }

  22. class Chain {
  23. public:
  24.   int head_;
  25.   int tail_;
  26.   int count_;
  27.   unsigned int duration_;
  28.   
  29.   Chain(int head, int tail, int count, unsigned int duration):
  30.     head_(head), tail_(tail), count_(count), duration_(duration) {}
  31.    
  32.   void Print() {
  33.     cout << "start_job: " << head_ << endl;
  34.     cout << "last_job: " << tail_ << endl;
  35.     cout << "number_of_jobs: " << count_ << endl;
  36.     vector<string> total = Convert(duration_);
  37.     cout << "job_chain_runtime: " << total[0] << ":" << total[1] << ":" << total[2] << endl;
  38.     vector<string> avg = Convert((int)(duration_ / count_));
  39.     cout << "average_job_time: " << avg[0] << ":" << avg[1] << ":" << avg[2] << endl;
  40.     cout << "-" << endl;
  41.   }

  42. private:
  43.   vector<string> Convert(int duration) {
  44.     vector<string> result;
  45.     int seconds = duration % (24 * 3600); // total displayable seconds
  46.     result.push_back(Format(seconds / 3600)); // hours
  47.     seconds %= 3600;
  48.     result.push_back(Format(seconds / 60)); // minutes
  49.     seconds %= 60; // seconds
  50.     result.push_back(Format(seconds)); // seconds;
  51.     return result;
  52.   }
  53.   
  54.   string Format(int input) {
  55.     if (input < 10) {
  56.       return "0" + to_string(input);
  57.     }
  58.     return to_string(input);
  59.   }
  60. };

  61. class JobRunner {
  62. public:
  63.   JobRunner() {
  64.     Reset();
  65.   }
  66.   
  67.   // Reset the states to redo the job logging.
  68.   void Reset() {
  69.     is_garbage_ = false;
  70.     graph_ = unordered_map<int, int>();
  71.     durations_ = unordered_map<int, int>();
  72.     in_degree_ = unordered_map<int, int>();
  73.     heads_ = unordered_set<int>();
  74.     unvisited_ = set<int>();
  75.     results_ = vector<Chain>();
  76.   }
  77.   
  78.   void Preprocess(const char* input) {
  79.     // To take std::cin as input to this function, you just need to replace
  80.     // the input argument type from "const char* " to "std::istream&" and
  81.     // comment out the following line of stringstream.
  82.     stringstream ssline(input);
  83.     string line;

  84.     while (getline(ssline, line, '\n')) {
  85.       if (!line.empty() && line[0] == '#') {
  86.         continue;
  87.       }
  88.       // cout << line << endl;
  89.       vector<int> numbers;
  90.       stringstream ssitem(line);
  91.       while (ssitem.good()) {
  92.         string number;
  93.         getline(ssitem, number, ',');
  94.         if (IsPositiveNumber(number)) {
  95.           numbers.push_back(stoi(number));
  96.         }
  97.       }
  98.       // cout << numbers.size() << endl;
  99.       if (numbers.size() != 3) {
  100.         is_garbage_ = true;
  101.         break;
  102.       }
  103.    
  104.       graph_[numbers[0]] = numbers[2];
  105.       durations_[numbers[0]] = numbers[1];
  106.       unvisited_.insert(numbers[0]);
  107.       if (in_degree_.find(numbers[0]) == in_degree_.end()) {
  108.         in_degree_[numbers[0]] = 0;
  109.         heads_.insert(numbers[0]);
  110.       }
  111.       in_degree_[numbers[2]]++;
  112.       if (heads_.find(numbers[2]) != heads_.end()) {
  113.         heads_.erase(numbers[2]);
  114.       }
  115.     }
  116.   }
  117.   
  118.   void GenerateOutput() {
  119.     // PrintStatesForDebug();

  120.     if (is_garbage_) {
  121.       cout << "Malformed Input" << endl;
  122.       return;
  123.     }

  124.     for (const auto& head : heads_) {
  125.       Chain current = Chain(head, graph_[head], 1, durations_[head]);
  126.       unvisited_.erase(head);
  127.       int next = graph_[head];
  128.       // Terminate if the next job does not end with 0.
  129.       while (next != 0 && durations_.find(next) != durations_.end()) {
  130.         UpdateChain(current, next);
  131.       }
  132.    
  133.       results_.push_back(current);
  134.     }
  135.   
  136.     // Processing the remaining cyclic graph.
  137.     while (!unvisited_.empty()) {
  138.     //  cout << ", unvisted: " << unvisited.size()
  139.         //  << ", durations: " << durations.size() << endl;
  140.    
  141.       int head = *unvisited_.begin();
  142.       Chain current = Chain(head, graph_[head], 1, durations_[head]);
  143.       unvisited_.erase(head);
  144.       int next = graph_[head];
  145.       while (unvisited_.find(next) != unvisited_.end()) {
  146.         UpdateChain(current, next);      
  147.       }
  148.       results_.push_back(current);
  149.     }
  150.   
  151.     sort(results_.begin(), results_.end(), [](const Chain& a, const Chain& b) {
  152.       return a.duration_ > b.duration_ ? true : (a.duration_ == b.duration_ ? a.head_ < b.head_ : false);  
  153.     });
  154.   
  155.     cout << "-" << endl;
  156.     for (auto& result : results_) {
  157.       result.Print();
  158.     }
  159.   }

  160. private:
  161.   void UpdateChain(Chain& current, int& next) {
  162.     unvisited_.erase(next);
  163.     current.tail_ = next;
  164.     current.count_++;
  165.     current.duration_ += durations_[next];
  166.     next = graph_[next];      
  167.   }

  168.   // Print states for debugging purpose only.
  169.   void PrintStatesForDebug() {
  170.     cout << "\ngraph and duration: " << endl;
  171.     for (const auto& p : graph_) {
  172.       cout << p.first << " -> " << p.second << " : " << durations_[p.first] << endl;
  173.     }
  174.    
  175.     cout << "\nindegree: " << endl;
  176.     for (const auto& p : in_degree_) {
  177.       cout << p.first << " : " << p.second << endl;
  178.     }
  179.   
  180.     cout << "\nheads: " << endl;
  181.     for (const auto& h : heads_) {
  182.       cout << h << " ";
  183.     }
  184.     cout << endl;   
  185.   }

  186.   bool is_garbage_;
  187.   unordered_map<int, int> graph_;
  188.   unordered_map<int, int> durations_;
  189.   unordered_map<int, int> in_degree_;
  190.   unordered_set<int> heads_;
  191.   // Ensure job id in order when encounted with circylic job chain.
  192.   set<int> unvisited_;
  193.   
  194.   vector<Chain> results_;
  195. };

  196. } // namespace Solution

  197. int main() {
  198.   /*
  199.   std::string line;
  200.   while (std::getline(std::cin, line)) {
  201.     std::cout << line << std::endl;
  202.   }
  203.   */
  204.   
  205.   const char* kInput1 =
  206.     "#first_job_id, runtime, next_job_id\n"
  207.     "1, 10, 23\n"
  208.     "3, 15, 7\n"
  209.     "23, 36, 0\n"
  210.     "7, 15, 0\n";
  211.   const char* kInput2 =
  212.     "#first_job_id, runtime, next_job_id\n"
  213.     "1, 60, 23\n"
  214.     "2, 23, 3\n"
  215.     "3, 12, 0\n"
  216.     "23, 30, 0\n";
  217.   const char* kInput3 =
  218.     "#first_job_id, runtime, next_job_id\n"
  219.     "1, 86000, 23\n"
  220.     "2, 23, 3\n"
  221.     "3, 12, 0\n"
  222.     "23, 400, 0\n";
  223.    
  224.   const char* kInput4 =
  225.     "#first_job_id, runtime, next_job_id\n"
  226.     "1, 1, 23\n"
  227.     "2, 3, 3\n"
  228.     "3, 4, 1\n"
  229.     "23, 2, 2\n"
  230.     "33, 15, 34\n"
  231.     "24, 25, 33\n"
  232.     "18, 35, 24\n";
  233.    
  234.   const char* kInput5 =
  235.     "#first_job_id, runtime, next_job_id\n"
  236.     "1, 1, 23\n"
  237.     "2, 3, 3\n"
  238.     "3, 400, 1\n"
  239.     "23, 2, 2\n"
  240.     "33, 15, 34\n"
  241.     "24, 25, 33\n"
  242.     "18, 35, 24\n"
  243.     "10, 15, 11\n"
  244.     "11, 16, 12\n"
  245.     "12, 17, 13\n"
  246.     "13, 18, 14\n"
  247.     "14, 19, 10\n";
  248.    
  249.   const char* kInput6 =
  250.     "#first_job_id, runtime, next_job_id\n"
  251.     "1, 1, 0\n";
  252.    
  253.   const char* kInput7 =
  254.     "#first_job_id, runtime, next_job_id\n"
  255.     "1, a, 0\n";
  256.    
  257.   // A node has two input branches.
  258.   const char* kInput8 =
  259.     "#first_job_id, runtime, next_job_id\n"
  260.     "1, 5, 2\n"
  261.     "2, 5, 3\n"
  262.     "3, 5, 4\n"
  263.     "4, 5, 0\n"
  264.     "6, 5, 7\n"
  265.     "7, 5, 3\n";
  266.    
  267.   // A node has two output branches.
  268.   const char* kInput9 =
  269.     "#first_job_id, runtime, next_job_id\n"
  270.     "1, 5, 2\n"
  271.     "2, 5, 3\n"
  272.     "3, 5, 4\n"
  273.     "4, 5, 0\n"
  274.     "6, 5, 7\n"
  275.     "7, 5, 0\n";
  276. //  cout << kInput << endl;

  277.   // I'm assumeing there is no multiple input/output branches in the job chains.
  278.   Solution::JobRunner runner;
  279.   runner.Preprocess(kInput9);
  280.   runner.GenerateOutput();

  281.   return 0;
  282. }

复制代码

评分

参与人数 1大米 +10 收起 理由
匿名用户-IGGK3 + 10

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-7S6UI  2023-9-12 05:29:27
RedAlice 发表于 2023-5-18 16:26
我三月份电面就挂了经历相似 把我过的CODE po下吧

请问层主过了oa吗
回复

使用道具 举报

🔗
RedAlice 2023-9-12 06:10:51 | 只看该作者
全局:

我的OA过了
回复

使用道具 举报

🔗
eric1527 2024-7-19 00:01:23 | 只看该作者
全局:
多谢楼主分享。
回复

使用道具 举报

🔗
arjiang 2024-10-6 13:14:40 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
RedAlice 2024-10-15 09:12:33 | 只看该作者
全局:
arjiang 发表于 2024-10-5 22:14
多谢分享. 请问你考虑了多个parent或多个child的情况么(仍保证不出现环)? 比如jobs 1->2, 1->3视为两条合 ...

这些不合法
回复

使用道具 举报

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

本版积分规则

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