记录一些刷HackerRank的Python模块的时候的小心得和体会,以及有趣的代码 HackerRank刷题之路---PythonHackerRank的Python模块的网页链接 由于绝大多数题目都很简单,适合初学者练练手,所以这里只记录一些有趣的题目和一些有趣的代码实现。Alphabet Rangoli此题目要求输入一个整数,打印出如下图形(此图为输
Very good problem to learn knapsack (complete knapsack in this case).My brutal-force solution in Python got AC too, which surprised me a bit. Here is ...
转载 2015-03-19 05:11:00
90阅读
2评论
---恢复内容开始---​​https://www.hackerrank.com/contests/world-codesprint-6/challenges/abbr​​给定两个串str和sub。对于每个str中的小写字母,可以变成大写,其他小写字母,能无条件删除,问其能否变成sub一开始的时候贪心,用个数组标记两个串中字母各有多少个,一直模拟。然后卡死在一组数据上。我也发现不了是什么数据。那么
原创 2022-10-20 11:13:39
79阅读
A coding problem. The trick is, some part of computation can be reused from last iteration. Check out my code:#include #include #include #include #inc...
转载 2015-04-16 12:30:00
234阅读
2评论
HackerRank - candies 【贪心】 Description Alice is a kindergarten teacher. She wants to give some candies to the children in her class. A...
转载 2018-03-01 21:28:00
144阅读
2评论
My first reaction was, total No. of strings - no. of palindromic strings. But looks like counting all palindromic strings is not that easy.. So it has...
转载 2015-04-30 15:30:00
66阅读
2评论
This is a super interesting bit problem. This link can be found in discussion panel:http://math.stackexchange.com/questions/712487/finding-xor-of-all-...
转载 2015-04-23 05:18:00
490阅读
2评论
Longest Common Subsequence in disguise.Python impl. has TLE in one case. And C++ is fine.#include #include #include #include #include #include #includ...
转载 2015-03-16 14:12:00
195阅读
2评论
Point: not necessarily contigous max sub array, at least one element should be selected:def maxSubarrCont(arr, n): ret = arr[0] curr = arr[0] ...
转载 2015-03-03 16:20:00
144阅读
2评论
All about pruning and duplication removal. Took me several submissions to get it AC:#include #include #include #include #include #include using namesp...
转载 2015-02-28 07:52:00
87阅读
2评论
The punch line to this problem is the support to very very large int handling. I tried C++ code for multiple times, but it only passed first 13~ cases
转载 2015-02-27 14:58:00
141阅读
2评论
黑客也就是英文hacker的音译,hacker这个单词源于动词hack,这个词在英语中有“乱砍、劈,砍”之意,还有一个意思是指“受雇于从事艰苦乏味的工作的文人”。hack的一个引申的意思是指“干了一件非常漂亮的事”.在早期的麻省理工学院里,“hacker”有“恶作剧”的意思,尤指那些手法巧妙、技术高明的恶作剧,可见,至少是在早期,黑客这个称谓并无贬义。  “破解不是学习使用一个
Solution 1:https://www.hackerrank.com/challenges/number-list/editorialReversed thought: total no. of subsets - no. of subsets without arr[i] > kSoluti...
转载 2015-05-11 05:08:00
103阅读
2评论
Typical tree recursion works. The key is: ANY node can be treated as the root, since it is about edge, not about node. This simplifies things a lot.#i...
转载 2015-04-27 14:14:00
242阅读
2评论
Really interesting problem! My 1st solution was DP based, like bottom-up pattern, but it got TLE since it is O(n^2). Then I thought there must be a O(...
转载 2015-04-16 14:52:00
274阅读
2评论
Typical greedy\recursion algorithm.#include #include #include #include #include #include using namespace std;struct Node{ Node() : pinx(0), nodeCnt...
转载 2015-04-17 14:16:00
94阅读
2评论
Kinda similar with another palindrome DP from LeetCode. Feel it, it is a bottom-up DP - palindrome subsequence.str = input()slen = len(str)dp = [[0 fo...
转载 2015-03-20 01:15:00
135阅读
2评论
Nothing special, just some corner casesn = int(input())arr = [int(i) for i in input().strip().split()]# Collect rec = []i = 0while i arr[i + 1]: ...
转载 2015-03-18 03:01:00
121阅读
2评论
https://www.hackerrank.com/challenges/angry-childrenAmong N ints, pick K with min 'unfairness' (max of k - min of k). Here's the strategy: larger numb...
转载 2015-02-27 06:47:00
235阅读
2评论
Really interesting problem. Naive solution would be O(n^3). But please note the pattern here: (i, j, k) -> (i + 1, j + 1, k) -> (i + 2, j + 2, k)... t...
转载 2015-05-08 07:23:00
404阅读
2评论
  • 1
  • 2
  • 3
  • 4
  • 5