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

Author Archives: Sheng

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

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

Posts navigation

← 1 … 32 33 34 35 →

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

  • Jay Bariya January 18, 2023 at 3:54 pm on Solution to Triangle by codilityI initially solved it using how Sheng did to just find the mere existence of a trianglular. My code can be modified to find all...
  • Jay Bariya January 17, 2023 at 1:23 am on Solution to Max-Product-Of-Three by codility100% Python solution. Hi @Sheng, I tried solving it without using sorting. Just min and max. I believe my complexity is O(N), but Codility shows...
  • Jay Bariya January 16, 2023 at 9:15 pm on Solution to Distinct by codilityUse a dictionary or just use a set. def solution(A): unique_dict = {} for int_val in A: unique_dict[int_val] = 0 return len(unique_dict.keys())
  • Jay Bariya January 8, 2023 at 10:34 pm on Solution to Min-Avg-Two-Slice by codilityPython solution- 100%. Detected time complexity - O(N). Even before looking at the solution, the proof that global minimum average lies in slices with 2...
  • Jay Bariya January 6, 2023 at 4:57 am on Solution to Genomic-Range-Query by codilityPretty neat and easy to understand solution. Thanks.
  • Jay Bariya January 3, 2023 at 1:02 am on Solution to Count-Div by codilityPython 100%. Time Complexity O(1). def solution(A,B,K): # solution for case K = 1 if K == 1: return B-A + 1 # solution for...
  • Jay Bariya January 2, 2023 at 10:55 pm on Solution to Passing-Cars by codilityPython solution - 100%. O(N) def solution(A): n_pairs= 0 to_east = 0 # iterate over directions for direction in A: # if direction is east,...
  • Jay Bariya December 31, 2022 at 11:53 pm on Solution to Missing-Integer by codility100% on correctness and performance. Detected Time Complexity - O(N) or O(NlogN). I've explained my code with comments. def solution(A): # sort the list A.sort()...
  • Jay Bariya December 30, 2022 at 7:05 pm on Solution to Max-Counters by codilityTime Complexity - O(N+M). 100%. List comprehension in the last step instead of directly applying max() inspired from one of the other comments on Python....

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