Facebook Phone Interview: Phone Number to Letter Combinations

VLOOKUP_fixed.py 立即下载

Input: string of digits of arbitrary length

output: print all possible letter combinations for those digits to screen.

// This is a typical DFS algorithm.
// Suppose we dont know the phone screen layout. we need to set a dictionary first.
// 
map<char, vector<char> > dict; // we use a map structure to map digits to letters.
vector<string> ret;
void createDict() {
    dict.clear();
    dict['2'].push_back('a'); dict['2'].push_back('b'); dict['2'].push_back('c');
    dict['3'].push_back('d'); dict['3'].push_back('e'); dict['3'].push_back('f');
    dict['4'].push_back('g'); dict['4'].push_back('h'); dict['4'].push_back('i');
    dict['5'].push_back('j'); dict['5'].push_back('k'); dict['5'].push_back('l');
    dict['6'].push_back('m'); dict['6'].push_back('n'); dict['6'].push_back('o');
    dict['7'].push_back('p'); dict['7'].push_back('q'); dict['7'].push_back('r'); dict['7'].push_back('s');
    dict['8'].push_back('t'); dict['8'].push_back('u'); dict['8'].push_back('v');
    dict['9'].push_back('w'); dict['9'].push_back('x'); dict['9'].push_back('y'); dict['9'].push_back('z');
}

// dfs algorithm.
void dfs(int dep, int maxDep, string& s, string ans) {
    if(dep == maxDep) {
        ret.push_back(ans);
        return;
    }
    for(int i = 0; i < dict[s[dep]].size(); ++i) {
        dfs(dep + 1, maxDep, s, ans+ dict[s[dep]][i]);
    }
}

vector<string> letterCombinations(string digits) {
    ret.clear();
    createDict();
    dfs(0, digits.size(), digits, "");
    return ret;
}

This is very straightforward to do it recursively. However, iterative is more elegant. 

Think it in this way: 

Suppose we have one digit, the output is straightforward, if we have two digits: 23, the output should be add the second digits' mapping to each first digit's mapping.

We can use a vector to store first digit's mapping, and loop through the mapping to add the second digit's mapping.

The total time complexity is (m ^ n) : m is the mapping digits' size, n is the total length of digits.

// do it iteratively.
vector<string> letterCombinations(string digits) {
  if(digits.size() == 0) return {};
  vector<string> maps{"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  vector<string> res;
  res.push_back("");
  for(int i = 0; i < digits.size(); ++i) {
    vector<string> backUp;
    for(int j = 0; j < maps[digits[i] - '0'].size(); ++j) {
      for(int k = 0; k < res.size(); ++k) {
        backUp.push_back(res[k] + maps[digits[i] - '0'][j]);
      }
    }
    res = backUp;
  }
  return res;
}

int main(void) {
  vector<string> res = letterCombinations("123");
  for(int i = 0; i < res.size(); ++i) {
    cout << res[i] << endl;
  }
}

YOLO26算法心电图十二导联目标检测+训练好的模型+368张数据集+pyqt可视化界面.zip 附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[导联I(I), 导联II(II), 导联III(III), 胸导联V1(V1), 胸导联V2(V2), 胸导联V3(V3), 胸导联V4(V4), 胸导联V5(V5), 胸导联V6(V6), 加压肢体导联aVF(aVF), 加压肢体导联aVL(aVL), 加压肢体导联aVR(aVR)] · 训练集:313 张 · 验证集:37 张 · 测试集:18 张 · 总计:368 张 该数据集聚焦于临床心电图信号的精准识别与定位,其核心检测目标为标准12导联心电图中的各个独立导联波形区域,涵盖肢体导联(I、II、III)与加压肢体导联(aVR、aVL、aVF),以及胸前导联(V1至V6),适用于心电图自动分析系统中对各导联位置的快速准确标注与分类。数据采集场景真实还原了医院心电图室或急诊监护环境下的标准心电图记录纸,波形清晰、基线稳定,具有高度临床参考价值。... 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 57 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9708** mAP50-95 | 0.6344 Precision | 0.8990 Recall | 0.9191 train/box_loss | 1.2231 train/cls_loss | 0.9703 val/box_loss | 1.2779 val/cls_loss | 0.... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。 立即下载

相关推荐

企业级AI助手平台 开箱即用的全栈AI平台,支持多智能体协同、Supervisor模式编排、多种决策模式、RAG技术和流程编排能力 支持多厂商大模型统一接入与管理,安全可控的企业知识库与高精度检索优化

企业级AI应用开发框架,支持多厂商大模型统一接入与管理,安全可控的企业知识库与高精度检索优化能力,提供可视化流程编排、自主决策智能体与多智能体协同调度,兼容主流 Agent Skill 协议,帮助企业与开发者零门槛快速构建安全、高效、可落地的AI智能体应用与行业解决方案。

如何找回忘记的Facebook密码

facebook营销密码If you don’t use a password manager, those complex passwords can be pretty hard to remember. If you’ve forgotten your Facebook password, you can’t really recover that same password, but it...

1万+

mysql数据目录迁移后表不存在_mysql 直接从date 文件夹备份表,还原数据库之后提示 table doesn`t exist的原因和解决方法...

补充:正常情况下,建议数据库备份最好用工具进行备份,通过拷贝数据库表进行数据迁移,不同的环境会出现各种不同的意外问题。背景:今天在整理一个网站的时候,操作系统由于系统自动更新导致一直出现系统蓝屏死机,唉,悲剧了,于是重新安装了系统 windows server 2008 enterprise 32bit。详情:系统安装完成后,重新配置之前那个网站,appache服务配好之后,再配置数据的时候是这样...

weixin_39628271的博客 2672

Facebook Phone Interview -- Move Zeros to Right (Easy)

March 22th, 2016. Move Zeros to the right end but keep the order of non-zero numbers. #include #inlcude #include using namespace std; // move Zeros to the right end of the array. // classi

ActiveCoder的博客 379

【强化学习】强化学习中,训练过程的稳定性是什么?该如何进行衡量?请详细进行解释

在强化学习中,训练过程的稳定性指的是算法在训练过程中表现出一致的行为,并且能够稳定地收敛到一个好的策略。收敛性:算法是否能够在有限的时间内收敛到一个近似最优的策略。鲁棒性:算法在不同的初始条件或环境扰动下的表现是否稳定。方差:算法在多次运行中表现出的变异程度。稳定的训练过程意味着算法的训练曲线平滑奖励信号变化小,且策略或价值函数的变化是渐进的。

wq6qeg88的博客 1628

群晖NAS实战:从零部署Container Manager与Docker代理配置全攻略

本文详细介绍了在群晖NAS上从零部署Container Manager与配置Docker代理的完整流程。针对国内用户常见的镜像拉取问题,提供了图形化界面与SSH命令行两种解决方案,并分享了MySQL容器部署的实战案例。文章特别强调了网络配置技巧和日常维护方法,帮助用户高效管理NAS上的容器应用。

weixin_29254673的博客 1300

Add One

#include #include using namespace std; /* Given an integer, add its binary number by 1 without using '+'. */ int addOne(int number) { long long int a = number; if(a >= INT_MAX) return -1; /

ActiveCoder的博客 2079

腾讯2020 unreal虚幻面试题

解析一下,腾讯的unreal客户端面试题: 1.lua性能优化的方向 申请的内存,是造成卡顿的原因之一,在C++与lua交互中,如果参数或者返回值有类变量,那么这个变量不会再交互的栈中存放数据,而会通过申请内存,再指定在交互,这样就造成卡顿,因此可以通过把C++的对象的每个参数分开单独传递,可以解决问题,当时我们游戏改完这个问题后,整体提升了2帧。 其实,主要是Tick循环中,减少与C++的交互,需要的数据不要每帧都去拿,其次,经常拿的一些数据(比方说主角信息),可以做一个lua缓存,...

qq_17347313的博客 1万+

LeetCode 91. Decode Ways

There are two ways to solve this problem. One is to solve it front-back, the other is back-front. I currently only wrote the back-front method: Suppose we have such a string:    a0, a1, a2.... ai, a

ActiveCoder的博客 954

BSD盲区检测系统性能要求及试验方法

盲区监测系统BSD通过安装在车辆后方的两颗毫米波雷达实时监测驾驶员视野盲区,当发现视野盲区内出现其它道路使用者时,通过左右后视镜上的警示灯向驾驶员发出报警。

未知艺术家的博客 2356

双目摄像头全景解析:从几何光学到深度智能

双目视觉系统基于仿生学原理,通过水平排列的双摄像头模拟人眼视差机制实现三维感知。其核心是通过标定、校正、匹配等算法流程,将视差转换为深度信息,最终生成三维点云。该系统在自动驾驶、机器人导航、工业检测等领域有广泛应用,但面临弱纹理、重复图案等挑战。未来发展趋势包括与事件相机、深度学习等技术的融合,进一步提升精度和动态性能。

reset2021的博客 120

Find the Thief (Facebook Interview)

Suppose there is a thief and n rooms. We can only any door to check whether the thief is there or not. during the night, the theif can either move left one room or right one room. Given a sequence of

ActiveCoder的博客 728

深度强化学习调参技巧:以DQN、DDPG、TD3、PPO、SAC等算法为例

深度强化学习调参技巧:以D3QN、DDPG、TD3、PPO、SAC算法为例

丨汀、的博客 3442

LeetCode 273. Integer to English Words

I changed the integer into string. If the length is not multiple of 3, append "0" ahead. Then, deal three digits by chunks. #include #include #include using namespace std; /* Convert a non-ne

ActiveCoder的博客 641

rk3399开发环境的介绍

由于Bluez的介绍文档有限,以及对Linux 系统/驱动概念、D-Bus 通信和蓝牙协议都有要求,加上网络上其实没有一个完整的介绍Bluez系列的文档,所以不管是蓝牙初学者还是蓝牙从业人员,都有不小的难度,学习曲线也相对较陡,所以我有了这个想法,专门对Bluez做一个系统性的介绍,尽可能的涵盖所有内容。

朝气蓬勃 708

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Subarray Sum to the given target value

Question: check if there is a subarray sum equals to the given target. This question should ask for clarifications. Whether the inputs are all positive, or it has negative numbers. 1: If all the num

ActiveCoder的博客 623

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Task Arrangement -- incomplete

Task schedule: Given a sequence of task like A B C, and a coldtime, which means you need to wait for that much time to start next[same] task. Now--- Input: string , n Output: the best task finishing

ActiveCoder的博客 556

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Facebook Phone Interview: 3, 4 Sum (Easy)

Facebook really usually has a high frequency of posting repetitive problems. This one is the typical 3Sum, 4Sum problem. Given an input array and a target value, find whether there are three/four

ActiveCoder的博客 450

LeetCode 28. Implement strStr()

Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. It is pretty hard to generalize KMP algorithm under stress and limited

ActiveCoder的博客 448

LeetCode 76. Minimum Window Substring

#include #include #include #include using namespace std; /* Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For

ActiveCoder的博客 413

Maximum value's random index

#include #include #include #include #include using namespace std; // naive method // Go through the array once, find the max and the number of occurrences (n) // Generate a random number (r) bet

ActiveCoder的博客 408

LeetCode. 314 Binary Tree Vertical Order Traversal

The basic idea to attach each node a col number. When goes to node->left. col -1, goes to right, col + 1. It will make things easier using a hashmap to store the nodes and correpsonding col number.

ActiveCoder的博客 395

Three Sum Variation.

/* find three numbers that sums to 0, every number can be used repeatly. (Someone said it can be solved using hashMap?) Follow up: what if any K numbers. */ #include #include #include using nam

ActiveCoder的博客 389

LeetCode 145. Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Stack Problem, One example

ActiveCoder的博客 384

Remove Nested Comments.

Comments can be single line using //, or multiple line using /* */ We can use two flags to make the begin and end of two types of comments. string removeComments(string str) { string res; bool s

ActiveCoder的博客 379
上一篇: Facebook Phone Interview -- Move Zeros to Right (Easy)
下一篇: Facebook Phone Interview: 3, 4 Sum (Easy)
ActiveCoder
博客等级 码龄11年 4粉丝 345原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值