HackerRank "Morgan and a String"
I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution:
for _ in range(int(input())):
a = input() + '['
b = input() + '[' output = ""
for _ in range(len(a) + len(b) - 2):
if a < b:
output += a[0]
a = a[1:]
else:
output += b[0]
b = b[1:] print(output)
Please note: '[' is the first char after 'Z'.
HackerRank "Morgan and a String"的更多相关文章
- HackerRank beautiful string
问题 https://vjudge.net/problem/HackerRank-beautiful-string 给一个字符串S,可以任意取走S中的两个字符从而得到另外一个字符串P,求有多少种不同的 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- *[hackerrank]Lexicographic paths
https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps 这题还是折腾很久的.题目意思相当于,比如有两个1两个0,那么 ...
- *[hackerrank]Sam and sub-strings
https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...
- [hackerrank]The Love-Letter Mystery
https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery 简单题. #include <cstdlib& ...
- *[hackerrank]ACM ICPC Team
https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team 这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过 ...
- Hackerrank 2020 February 2014 解题报告
Hackerrank 2020 February 2014 解题报告 比赛链接 Sherlock and Watson (20分) 题意:给定一个数组,向右平移K次,然后有Q个询问,问第x位置上是几 ...
- hackerrank:Almost sorted interval
题目链接:https://www.hackerrank.com/challenges/almost-sorted-interval 题目大意: 定义一个“几乎单调”区间(区间最小值在最左面,最大值在最 ...
- 【转】morgan stanley 电面面经新鲜出炉
楼楼早上上午大概11点接到的电话,一个声音炒鸡好听的GG,说他是来自morgan stanley的,想和我约一下店面时间.我一听,真是戳不及防,掐指一算,online的IKE测试已经过去20几天了吧, ...
随机推荐
- HTML-day-1-HTML基础知识
HTML基础知识 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- 递归---n皇后
---恢复内容开始--- #include "stdafx.h" #include <iostream> #include <fstream> //文件流 ...
- 解决f.lux总是弹框定位
解决f.lux总是弹框定位,直接导入成功定位的注册表文件即可. 以下保存为f.lux.reg 双击导入即可. Windows Registry Editor Version 5.00 [HKEY_CU ...
- Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现(转)
Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现 zouxy09@qq.com http://blog.csdn.net/zouxy09 自己平时看了一些论文, ...
- Gulp 总结
Gulp介绍 Gulp是一个前端开发的自动化构建工具.前端开发往往需要把LESS/SCSS文件进行编译成CSS文件,javascript多文件合并成一个文件并压缩以及一些其他需要重复性操作的工作.而G ...
- C++ Primer : 第十一章 : 关联容器之概述、有序关联容器关键字要求和pair类型
标准库定义了两种主要的关联容器:map和set map中的元素时一些关键字-值(key-value)对,关键字起到索引的作用,值则表示与索引相关的数据.set中每个元素只包含一个关键字,可以完成高效的 ...
- zboot/xtract.c
/* * linux/zBoot/xtract.c * * Copyright (C) 1993 Hannu Savolainen * * Extracts the system imag ...
- tulterbot遥感操作使用Interactive Markers--12
原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 1.安装ros indigo功能包: sudo apt-get install ros-indigo-t ...
- 通过joystick遥感和按键控制机器人--11
原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 1.首先安装joystick遥控器驱动: sudo apt-get install ros-indigo ...
- LeetCode(228) Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...