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

Tag Archives: C

Solution to Distinct by codility

18 Mar

Question: https://codility.com/demo/take-sample-test/distinct Question Name: Distinct In this question, the expected worst-case time complexity is O(N*log(N)). Thus the designed, or says official, solution would be sort the input and travel them. This solution is practically good. And it is shown as … Read More »

C/C++, Codility, Python C, codility, python 48 Comments

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

13 Oct

Before solving this problem, we introduce a simple library of stack with integers. Many following questions need an integer stack. Not to reinvent the wheel in our following solutions, we make a standalone integer stack library. Actually, we should do … Read More »

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

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

10 Oct

The first part of this question is easy: use a set of stacks to mimic a single stack. In the second part, we need to implement a new method as popAt(int index) to make a pop operation on a specific … Read More »

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

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

31 Jul

In my solution, I used a structure with two traditional stacks. One of them is used to store the original elements. The other is used to store the latest minimum elements. At any time, the top element in the second … Read More »

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

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

19 Jul

I used a different solution from the ones in the original book. In the first official solution in the book, one stack might be full while another is empty. The space utilization is bad. In the second official solution, once … Read More »

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

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

11 May

There is a similar and easier question: how to check if an array is a palindrome? Or equivalently, how to check if a double linked list is a palindrome? The three solutions in the original question work well for these … Read More »

C/C++, Solutions-CTCI C, CTCI 2 Comments

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

10 May

There is a follow up question: how to determine whether two linked lists, to say list1 and list2, intersect each other. Two solutions are available for this problem. On one hand, we could link the end of list1 to the … Read More »

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

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

9 May

The official solution for the backward problem is quite good. In contrast, there are two improvable places in the official solution for the forward problem (the follow up question). On one hand, in the official implement, the list is double … Read More »

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

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

Posts navigation

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

  • raul April 28, 2022 at 8:50 am on Solution to Genomic-Range-Query by codilityHi Sheng, i've made a similar code, that got 100/100 as well an it ilustrates pretty well what you're trying to say: def solution(S, P,...
  • raul April 27, 2022 at 9:06 am on Solution to Count-Div by codilitySorry, on (B-A)/K or (B-(A – A%K))/K + 1 it should've been (B-(A – A%K))/K or (B-A)/K + 1
  • raul April 27, 2022 at 9:00 am on Solution to Count-Div by codilityI don't think that anyone will be able to give you a more complete answer then Rachel did, although I'll try to make it simpler:...
  • raul April 25, 2022 at 10:49 pm on Solution to Perm-Check by codilityMy 100% solution using python: def solution(A): i = 0 xor = 0 for n in A: i += 1 xor ^= i ^ n...
  • raul April 25, 2022 at 10:27 pm on Solution to Frog-River-One by codilityVery interesting approach. Haven't tried in Java, although, I've recreated the same logic using python and it works wonders. If anyone's curious, the python code...
  • raul April 25, 2022 at 10:16 pm on Solution to Frog-River-One by codilitySorry guys, i tried to make the code look more pleasent before posting here, but even trying to use the same principle to solve in...
  • raul April 25, 2022 at 9:51 pm on Solution to Frog-River-One by codilityAnother 100/100 aproach in python: def solution(X, A): x = list(range(1, X + 1)) sum_x = sum(x) i = -1 while(len(A) > 0 and sum_x...
  • Raul April 18, 2022 at 1:59 pm on Solution to Perm-Missing-Elem by codilityI made it like this: def solution(A): if A == []: return 1 A = sorted(A) s = ((len(A) + 1) * ((len(A) + 1)...
  • Sheng April 15, 2022 at 9:26 pm on Solution to Tie-Ropes by codilityPlease re-read the question: given an integer K and a non-empty array A of N integers, returns the maximum number of ropes of length greater...

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
© 2022 Code Says
Powered by WordPress / Theme by Design Lab
  • Contact Me
  • About Me
  • Privacy Policy