📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
回复: 20
跳转到指定楼层
上一主题 下一主题
收起左侧

献上19年亚麻 intern OA2已知的11题的C++正确代码

全局:

2019(7-9月) 码农类General 硕士 实习@amazon - 内推 -   | | | 应届毕业生

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

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

x
亚麻OA2两道题所有case全过, 还是挂了, 反正留着也没用了, 不如发出来大家看看.

题目是大家之前总结的11道题的, 题目描述我没存下来, 但是看代码的话函数名能认出来.

代码是C++写的, 顺便还带有一个可以把各种C++常用数据结构像python一样直接print的调试类.哈哈哈.
各位看官求加米安慰安慰

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <random>
#include <unordered_map>
#include <stack>
#include <deque>
#include <algorithm>
#include <unordered_set>
#include <limits>
#include <map>
#include <functional>
using namespace std;

class Debug
{
public:
        template<template<class, class...> class ContainerType, class ValueType, class... Args>
        void print(const ContainerType<ValueType, Args...>& c)
        {
                        for (const auto& v : c)
                        {
                                cout << v << endl;
                        }
        }

        template<template<class, class, class> class ContainerType, class ValueType, class Cmp>
        void print(ContainerType<ValueType, vector<ValueType>, Cmp> q)
        {
                        while (!q.empty())
                        {
                                auto value = q.top();
                                cout << value << endl;
                                q.pop();
                        }
        }

        template<class T>
        void print(stack<T, deque<T>>& c)
        {
                while (!c.empty())
                {
                        auto value = c.top();
                        cout << value << endl;
                        c.pop();
                }
        }

        template<class T>
        void print(queue<T, deque<T>>& c)
        {
                while (!c.empty())
                {
                        auto value = c.front();
                        cout << value << endl;
                        c.pop();
                }
        }

private:
        template<class T, class U>
        friend ostream& operator<< (ostream& out, const pair<T, U>& p);
};

template<class T, class U>
inline ostream& operator<< (ostream& out, const pair<T, U>& p)
{
        out << "(" << p.first << "," << p.second << ")";
        return out;
}


/*1111111111111111111111111111111111111111111111111111111111*/
vector<int> two_sum_closet(vector<int>& nums, int target)
{
        sort(nums.begin(), nums.end());
        int n = nums.size(), res_l, res_r, l = 0, r = n - 1, diff = numeric_limits<int>::max();
        while (l < r)
        {
                if (abs(nums[l] + nums[r] - target) < diff)
                {
                        res_l = l, res_r = r;
                        diff = abs(nums[l] + nums[r] - target);
                }
                if (nums[l] + nums[r] > target) --r;
                else ++l;
        }
        return{ nums[res_l], nums[res_r] };
}

/*222222222222222222222222222222222222222222222222222*/
class Record {
public:
   int id, score;
   Record
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
d[1];
                                ++dist;
                        }
                        x -= d[0];
                        y -= d[1];
                        --dist;
                        if (dists[x][y] > dist) {
                                dists[x][y] = dist;
                                if (x != destination[0] || y != destination[1]) q.push({ x, y });
                        }
                }
        }
        int res = dists[destination[0]][destination[1]];
        return (res == INT_MAX) ? -1 : res;
}

/*11   11   11   11   11   11   11   11   11   11   11   11   11   11   11   11   11   11*/
vector<vector<int>> k_closest_neibers(vector<vector<int>>& points, int K)
{
        auto cmp = [](const vector<int>& p1, const vector<int>& p2) {
                return p1[0] * p1[0] + p1[1] * p1[1] < p2[0] * p2[0] + p2[1] * p2[1];
        };
        using type = priority_queue<vector<int>, vector<vector<int>>, decltype(cmp)>;
        type pq(cmp);
        for (auto point : points)
        {
                pq.emplace(point);
                if (pq.size() > K) pq.pop();
        }
        vector<vector<int>> res;
        while (!pq.empty())
        {
                res.emplace_back(pq.top()); pq.pop();
        }
        return res;
}


int main()
{
        vector<int> v{ 1, 3, 4, 7, 10 };
        vector<vector<int>> vv{ { 8, 4, 7 }, { 6, 5, 9 } };
        auto r = two_sum_closet(v, 15);
        auto r1 = count_number_of_substrings_with_exactly_k_distinct_characters("abafg", 2);
        /*auto r2 = maximum_minimum_path(vv);
        auto r3 = find_a_substring_of_size_K_such_that_there_is_exactly_one_character_that_is_repeated_once("awaglk", 4);
        Debug d;*/
        //d.print(r3);
        cout << r1 << endl;
        system("pause");
        return 0;
}



补充内容 (2019-2-12 09:01):
楼主是2.7的due

评分

参与人数 13大米 +38 收起 理由
ElvenZhou + 3 给你点个赞!
huhaoqi + 3 心疼,c++真的玄学...
DORTMUND09 + 3 很有用的信息!
2ndpoet + 3 很有用的信息!
白叨叨 + 3 很有用的信息!

查看全部评分


上一篇:airbnb背靠背电面过经
下一篇:亚麻 现场 面
推荐
 楼主| 023张教授 2019-2-16 05:28:13 | 只看该作者
全局:
amandagranger 发表于 2019-2-16 05:15
谢谢楼主分享,想请问楼主c++比如传参数进去是会以什么形式传过去。传vector a还是int*

OA2里我没记错的话应该是用的vector
回复

使用道具 举报

推荐
 楼主| 023张教授 2019-2-23 15:08:32 | 只看该作者
全局:
morgar2 发表于 2019-2-23 15:00
求问楼主知道挂的原因吗?testcase都过了是为啥不move了啊?(还没做oa2瑟瑟发抖。

没告诉我原因呢...
我看有人改错全对, OA2 case全国也....
回复

使用道具 举报

推荐
morgar2 2019-2-23 15:13:35 | 只看该作者
全局:
023张教授 发表于 2019-2-23 15:08
没告诉我原因呢...
我看有人改错全对, OA2 case全国也....

诶不知道为啥下面的帖子回了两遍……
回复

使用道具 举报

🔗
ff12 2019-2-12 08:59:27 | 只看该作者
全局:
请问楼主怎么确认挂了啊?有邮件通知吗?
回复

使用道具 举报

🔗
 楼主| 023张教授 2019-2-12 09:00:25 | 只看该作者
全局:
ff12 发表于 2019-2-12 08:59
请问楼主怎么确认挂了啊?有邮件通知吗?

是滴, 我收到了邮件, 我是2.7due
回复

使用道具 举报

🔗
ff12 2019-2-12 09:01:18 | 只看该作者
全局:
023张教授 发表于 2019-2-12 09:00
是滴, 我收到了邮件, 我是2.7due

我去。。好紧张

请问啥时候收到的邮件呀?
回复

使用道具 举报

🔗
 楼主| 023张教授 2019-2-12 09:02:32 | 只看该作者
全局:
ff12 发表于 2019-2-12 09:01
我去。。好紧张

请问啥时候收到的邮件呀?

我是今天早上收到的.
回复

使用道具 举报

🔗
tianyiwu 2019-2-12 12:24:27 | 只看该作者
全局:
哇楼主是因为HC被挂了吗 OA1刚做完的瑟瑟发抖
回复

使用道具 举报

🔗
 楼主| 023张教授 2019-2-12 12:35:25 | 只看该作者
全局:
tianyiwu 发表于 2019-2-12 12:24
哇楼主是因为HC被挂了吗 OA1刚做完的瑟瑟发抖

不知道诶... 就说不move forward了...
回复

使用道具 举报

🔗
amandagranger 2019-2-16 05:15:18 | 只看该作者
全局:
谢谢楼主分享,想请问楼主c++比如传参数进去是会以什么形式传过去。传vector<int> a还是int*
回复

使用道具 举报

🔗
amandagranger 2019-2-16 06:20:17 | 只看该作者
全局:
023张教授 发表于 2019-2-16 05:28
OA2里我没记错的话应该是用的vector

谢谢楼主耐心回复!祝你offer多多
回复

使用道具 举报

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

本版积分规则

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