记录一些刷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
83阅读
2评论
---恢复内容开始---​​https://www.hackerrank.com/contests/world-codesprint-6/challenges/abbr​​给定两个串str和sub。对于每个str中的小写字母,可以变成大写,其他小写字母,能无条件删除,问其能否变成sub一开始的时候贪心,用个数组标记两个串中字母各有多少个,一直模拟。然后卡死在一组数据上。我也发现不了是什么数据。那么
原创 2022-10-20 11:13:39
55阅读
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
197阅读
2评论
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
98阅读
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
214阅读
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
234阅读
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
77阅读
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
124阅读
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
113阅读
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
230阅读
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
139阅读
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
58阅读
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
459阅读
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
155阅读
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
125阅读
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
73阅读
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
137阅读
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
365阅读
2评论
Please note input constraints. String length will not exceed 100, which means, we can use relatively naive representation\calculation for anagrams: so...
转载 2015-04-30 13:29:00
264阅读
2评论
  • 1
  • 2
  • 3
  • 4
  • 5