Skip to content

Code Says

C code. C code run. Run code run… please!

  • Home
  • Cracking the Coding Interview
  • Codility
  • Jobdu OJ
  • LeetCode
  • Privacy Policy
  • Contact Me
  • Home
  • Cracking the Coding Interview
  • Codility
  • Jobdu OJ
  • LeetCode
  • Privacy Policy
  • Contact Me

Category Archives: C/C++

Unofficial C Solution to Problem 2.4 in Cracking the Coding Interview (5th Edition)

25 Apr

The question is one step in the quick sort algorithm. The idea is to rearrange the list so that the smaller nodes than pivot are previous to all other nodes. More details could be found on Wikipedia. In the implements … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 2.3 in Cracking the Coding Interview (5th Edition)

21 Apr

The description of this question is not quite clear. What does “given only access to that node” exactly mean? If we cannot read any other node, it is impossible to finish the work. If we could only read the node, … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 2.2 in Cracking the Coding Interview (5th Edition)

20 Apr

In the book, the author introduces many different methods. As the author indicates, the two-pointer iterative solution is the best. In contrast, the recursive method is less effective but quite interesting. It might be useful in some cases. I only … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 2.1 in Cracking the Coding Interview (5th Edition)

16 Apr

There are two solutions for this question. The first one is with hash table, thus needs more space but less time. The second one needs no additional space but more time. In the first solution, I choose to use the … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 1.8 in Cracking the Coding Interview (5th Edition)

12 Apr

If string str1 is a rotation of string str2, it must holds two conditions: The length of str1 equals to the length of str2; There is at least a set of two string A and B, such that str1=AB and … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 1.7 in Cracking the Coding Interview (5th Edition)

23 Mar

In this question, we have to travel the matrix twice. In the first time, we need to record which rows and columns contain zero element. And in the second round, we will set these rows and columns entirely zero. By … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 1.6 in Cracking the Coding Interview (5th Edition)

22 Mar

This question asks us to rotate an N by N matrix. Each element in the matrix is a pixel of an image, and represented by 4 bytes. The question did not indicate the length of byte. And I assume the … Read More »

C/C++, Solutions-CTCI C, CTCI Leave a comment

Unofficial C Solution to Problem 1.5 in Cracking the Coding Interview (5th Edition)

20 Mar

Generally, this question requires us to do a length encoding of an string. For example, after compression, the string “aaaabb” should become “a4b2”. If the compression could not shorten the string, the program will leave original string unchanged. I solve … Read More »

C/C++, Solutions-CTCI C, CTCI 1 Comment

Find a Duplicate Item In an Array of Shuffled Consecutive Integers

16 Mar

Question: if you hava an array with n integers. These integers are in random order. And each interger is between 1 and n-1, including 1 and n-1. Additionally, there is one and only one integer, which appears twice, while all … Read More »

C/C++, Interview Questions, Python C, Interview, python 3 Comments

Some Methods to Get the Number of Digits in An Integer, and Their Performance (2)

6 Mar

In this article, an stable-cost method is proposed and tested. Previously, the test result showed, the performance of brute force method is the best. Let the number of digits be n. In the best case, in which the integer is … Read More »

C/C++ C Leave a comment

Posts pagination

← 1 2 3 →

Guideline for Comments

tl;dr: Please put your code into a <pre>YOUR CODE</pre> section.

Hello everyone!

If you want to ask a question about the solution. DO READ the post and comments firstly.

If you had some troubles in debugging your solution, please try to ask for help on StackOverflow, instead of here.

If you want to post some comments with code or symbol, here is the guidline.

1. To post your code, please add the code inside a <pre> </pre> section (preferred), or <code> </code>. And inside the pre or code section, you do not need to escape < > and &, e.g. no need to use &lt; instead of <.

2. To use special symbols < and > outside the pre block, please use "&lt;" and "&gt;" instead.

3. If you have a comment with lots of < and >, you could add the major part of your comment into a <pre class="decode:true crayon-inline "> YOUR COMMENTS </pre> section.

Finally, if you are posting the first comment here, it usually needs moderation. Please be patient and stay tuned. Thanks!

CodeSays.com Admin

Recent Comments

  • sol
    February 15, 2025 at 6:28 am
    on Solution to Polygon-Concavity-Index by codility
    Your solution is wrong. you don't sort the points. For the following input it will return 0: (-1, 3), (-2, 1), (1, 2), (3, 1),...
  • Fabien
    November 7, 2024 at 4:42 am
    on Unofficial Solutions to the Training by Codility
    Similar but more compact solution using C++17 or later: #include <stack> #include <vector> using namespace std; using point = pair<int, int>; stack<point> pending; void explore(const...
  • Ovi
    February 12, 2024 at 11:14 pm
    on Solution to Min-Perimeter-Rectangle by codility
    Exactly my question too. I tried something very similar to Sheng's solution, importing the math module and using sqrt(). Codility marked it only as 80%,...
  • Doron Ben Ari
    February 11, 2024 at 4:10 am
    on Solution to Min-Avg-Two-Slice by codility
    Inspired by Sheng's great solution, I wrote the following proof: Assume you found the slice with minimal average. Assume the first two consecutive elements of...
  • Ovi
    February 4, 2024 at 9:03 am
    on Solution to sigma2012 (Stone-Wall) by codility
    def solution(H): heights = H # geometric logic: the blocks need to be cuboid, all sides are rectagular. Nothing fancy, means that the angles...
  • Ovidiu Oprea
    February 2, 2024 at 11:06 am
    on Solution to Fish by codility
    It's the reason why it took me 2 weeks to finish this task (in the context of adult life with non-dev job). I was trying...
  • Ovi
    January 15, 2024 at 2:40 pm
    on Solution to Brackets by codility
    Thanks for this blog post! I was banging my head against the wall thinking this is a simple / short solution, where you just build...
  • parikshit verma
    July 5, 2023 at 8:26 am
    on Solution to Missing-Integer by codility
    def missingnum(a): st=min(a) en=max(a) b=set(range(1,en+2)) if (en<1 or st>1) : return 1 else: return min(b-set(a))
  • Pavankumar Nandeshwar
    June 26, 2023 at 8:07 am
    on Solution to Dwarfs-Rafting by codility
    Ok fixed it. gives 100%: int solution(int N, string &S, string &T) { int q = N / 2 * N / 2; int lf...

Categories

  • Announcement
  • C/C++
  • Codility
  • Interview Questions
  • Java
  • Jobdu OJ
  • LeetCode
  • Linux
  • Others
  • Python
  • Solutions-CTCI
  • SQL

Tags

algorithm AppFog C codility Crawler CTCI Hash Set Interview Linux LMR pcapy PHP python rotation shuffle Utility WordPress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2026 Code Says
Powered by WordPress / Theme by Design Lab
  • Contact Me
  • About Me
  • Privacy Policy
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.