CrackingTheCodingInterview | Solutions to exercises from the book Cracking | Learning library
kandi X-RAY | CrackingTheCodingInterview Summary
kandi X-RAY | CrackingTheCodingInterview Summary
Solutions to exercises from the book "Cracking the Coding Interview"
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CrackingTheCodingInterview
CrackingTheCodingInterview Key Features
CrackingTheCodingInterview Examples and Code Snippets
Community Discussions
Trending Discussions on CrackingTheCodingInterview
QUESTION
I am trying to understand space complexity of the following piece of code. The code compresses Strings from "aabbbb" to "a2b4". The question is Question 5, Chapter 1 from Cracking the coding interview version 5 (2013) and the code is taken from the solutions
...ANSWER
Answered 2018-Mar-06 at 13:16You are asking about the space complexity of compressBetter
, which includes a call to countCompression
, but also performs additional work.
While the space complexity of countCompression
is indeed O(1)
, compressBetter
has linear space complexity (i.e. O(N)
) in the worst case (where no two consecutive characters of the input String
are equal), since it produces a StringBuffer
of 2N characters in that case.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CrackingTheCodingInterview
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page