• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:33
CEST 03:33
KST 10:33
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 1 - Final Week4[ASL19] Finals Recap: Standing Tall10HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced6Weekly Cups (June 30 - July 6): Classic Doubles6[BSL20] Non-Korean Championship 4x BSL + 4x China10Flash Announces Hiatus From ASL70
StarCraft 2
General
RSL Revival patreon money discussion thread The GOAT ranking of GOAT rankings We need to be discussing a new patch right now! Firefly given lifetime ban by ESIC following match-fixing investigation RSL Season 1 - Final Week
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament $25,000 Streamerzone StarCraft Pro Series announced WardiTV Mondays
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
BW General Discussion A cwal.gg Extension - Easily keep track of anyone ASL20 Preliminary Maps BGH Auto Balance -> http://bghmmr.eu/ Script to open stream directly using middle click
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues Last Minute Live-Report Thread Resource! [BSL20] Non-Korean Championship 4x BSL + 4x China
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile CCLP - Command & Conquer League Project Stormgate/Frost Giant Megathread The PlayStation 5 Nintendo Switch Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Accidental Video Game Porn Archive Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 542 users

The Big Programming Thread - Page 897

Forum Index > General Forum
Post a Reply
Prev 1 895 896 897 898 899 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Acrofales
Profile Joined August 2010
Spain17974 Posts
July 05 2017 21:40 GMT
#17921
honestly, I'm not sure you can get much more optimized than travis's idea with a slight modification:

1. run through the string and dump each index into a bucket with that letter (if it's not a letter, ignore it, and convert everything to lower case just in case.
2. remove all buckets with size != 1.
3. find the remaining lowest index and return its key.

It's O(n). Technically O(nm) where m is the size of your alphabet, but even including all unicode characters, it's not that bad in the grand scale of things.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-07-05 21:44:04
July 05 2017 21:41 GMT
#17922
On July 06 2017 06:15 Manit0u wrote:
Show nested quote +
On July 06 2017 05:28 mahrgell wrote:
On July 06 2017 05:16 Blisse wrote:
Am I missing something? Thought this was really straightforward?

+ Show Spoiler +

char find_first_nonunique_character(string input_string) {
set<char> characters;

for (char& c: input_string) {
if (characters.contains(element)) {
return element;
} else {
characters.insert(element);
}
}

throw IllegalArgumentException("Input only has unique characters");
}



char find_first_unique_character(string input_string) {
map<char, int> characters_count;

for (char& c: input_string) {
if (characters_count.count(c) == 0) {
characters_count.insert(element, 1);
} else {
characters_count[element] += 1;
}
}

for (char& c: input_string) {
if (characters_count.count(c) == 1) {
return c;
}
}

throw IllegalArgumentException("Input has no unique characters");
}


your find unique doesnt work and will always return the first character of the string, given that it surely will have an entry in your map, thus the count(c) will always return 1 on it.

And even if you fix that bug in your code, I think it was never argued that this problem is a challenge to solve, but the question is how to solve it efficiently. And that optimization is the way more tricky part with a lot of probably interesting potential ideas.
Using maps is certainly something I would avoid in that regard!


Actually, it's an algorithms interview question everyone is asked at my company. Making it optimal isn't important. Making it work is semi-important (good attempts count, even if they fail somehow - my initial solution could enter an infinite loop but I've corrected it when it was pointed out and it was fine). 90% of the candidates can't make it past this test

My pretty shitty solution during the interview:

letter = string.shift

foreach another_letter in string
if letter == another_letter
delete all copies of letter from string
reset

return letter


Obviously, it was a bit more complicated, since I've decided to do it in C for whatever reason. The only optimization was that with each pass it had to go through smaller char arrays (but still, it was quite a bit of work). My mind simply went blank and I went down to absolute basics of programming, without using any existing libraries or built-in functions for it.



if it makes you feel better I think that's a really creative solution
and if you were looking for only letters you could simply remove all non-letter characters as soon as you saw them too

so even though it might sound awful I am pretty sure that solution is O(n)
just not the best coefficient
BrTarolg
Profile Blog Joined June 2009
United Kingdom3574 Posts
July 05 2017 22:01 GMT
#17923
So I'm going to do a short data science course in LSE later this summer. My plan is to leverage my maths background and just run head first into data science, hopefully in a year I'll be useful and have a hirable and valuable skillset
TheEmulator
Profile Blog Joined July 2010
28087 Posts
Last Edited: 2017-07-05 22:13:37
July 05 2017 22:13 GMT
#17924
On July 06 2017 04:58 NovemberstOrm wrote:
poor guy, just came across this lol

+ Show Spoiler +

I don't personally have a job in the industry yet (gonna start applying soon hopefully) so I'm not 100% sure how things work in a real office environment, but this doesn't really feel like the junior devs fault. Or at least, he fucked up but shouldn't have had the ability to fuck up that hard in the first place from what I understand.

I'll watch the video when I have time, but I remember seeing that story on reddit lol.
Administrator
NovemberstOrm
Profile Blog Joined September 2011
Canada16217 Posts
Last Edited: 2017-07-05 22:27:09
July 05 2017 22:26 GMT
#17925
On July 06 2017 07:13 TheEmulator wrote:
Show nested quote +
On July 06 2017 04:58 NovemberstOrm wrote:
poor guy, just came across this lol

+ Show Spoiler +
https://www.youtube.com/watch?v=vT6wQFhLpro

I don't personally have a job in the industry yet (gonna start applying soon hopefully) so I'm not 100% sure how things work in a real office environment, but this doesn't really feel like the junior devs fault. Or at least, he fucked up but shouldn't have had the ability to fuck up that hard in the first place from what I understand.

I'll watch the video when I have time, but I remember seeing that story on reddit lol.

Yeah definitely not his fault, the company had a very poor setup. Not even having proper backups is just stupid.
Moderatorlickypiddy
bo1b
Profile Blog Joined August 2012
Australia12814 Posts
July 05 2017 22:38 GMT
#17926
Regarding the first non unique letter, a hash table should get it extremely quickly. Something pretty close to O(1), unless I've really forgotten how they work.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
July 05 2017 22:45 GMT
#17927
you can't do it in O(1) because you have to look at every element of the string (unless there is some absolutely insane trick I am not aware of)
mahrgell
Profile Blog Joined December 2009
Germany3943 Posts
July 05 2017 23:00 GMT
#17928
On July 06 2017 07:45 travis wrote:
you can't do it in O(1) because you have to look at every element of the string (unless there is some absolutely insane trick I am not aware of)

Pretty much that.

As you have to go over the entire string anyway, I'm actually quite confident that my solution from the previous page should be close to the optimum. There is no need at all to count how often each letter occurs, all you need is save the first index it occurs and have 2 void values for "has not occured yet" (0 in my code) and "has occured at least 2 times" (INF in my code)

It's idea can also simply be adapted to what ever alphabet one wants to consider eligable.

Iterate once over the string, then iterate once over the alphabet. All operations are direct access, no sorting, finding, middle inserting or anything similar potentially time consuming is required.

Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-07-05 23:43:16
July 05 2017 23:35 GMT
#17929
--- Nuked ---
bo1b
Profile Blog Joined August 2012
Australia12814 Posts
Last Edited: 2017-07-06 00:24:44
July 05 2017 23:52 GMT
#17930
That's exactly what I'm talking about, and the search time should be somewhere between O(1) to O(2) on average. I can't think of a scenario where it's greater then O(2), but I can think of a scenario where it's significantly less.

Hope I'm not horrible wrong rofl.

I'm an idiot, I don't mean O(1), I mean something else.
Zocat
Profile Joined April 2010
Germany2229 Posts
Last Edited: 2017-07-06 02:58:14
July 06 2017 02:50 GMT
#17931
In an interview question, just show the obvious n^2 solution. As Manit0u said most people already fail there.

If they ask you to optimize ask "Does the profiler show this as a bottleneck?" Gj, you know about premature optimization.

Ask what you are optimizing for (speed, memory, readability ...). You can probably write some unreadable code that is super fast. Thanks for not doing that.

Do whatever you want and explain your thoughts. Histograms. Frequency of English alphabet. Whatever.
dsyxelic
Profile Joined May 2010
United States1417 Posts
July 06 2017 04:03 GMT
#17932
On July 06 2017 08:35 Nesserev wrote:
Show nested quote +
On July 06 2017 07:45 travis wrote:
you can't do it in O(1) because you have to look at every element of the string (unless there is some absolutely insane trick I am not aware of)

I think he's talking about an approximately constant lookup in a properly implemented hashmap and using a nicely distributed hash function.

That said, something to note: bucket sort and radix sort should be used when the internal structure allows us to pass through all the elements only k times (k being the length of a string, the max amount of digits, etc.).
No reason to do it in this case.

s  = "fqkmjsdfjnqsmq" // k is first unique letter
m = {}

for c in s:
if c not in m:
m[c] = 1
else:
m[c] += 1

for c in s:
if m[c] == 1:
print(c) // prints solution
break


Does that mean for a string length of 10 characters, it would require us to pass through each element 10 times each?

How would radix sort work for a single string?

Did a bit of reading on it since I only vaguely heard about radix sort before and I understand how it works for a group of strings or numbers but not for a single one.

Just to confirm, for a list of 10 numbers with max length of a number being 10 digits, it would take 10*10=100 passes right?

TL/SKT
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
July 06 2017 06:06 GMT
#17933
--- Nuked ---
dsyxelic
Profile Joined May 2010
United States1417 Posts
July 06 2017 06:47 GMT
#17934
Ah I see, thanks that was pretty insightful and we did not cover radix sort in my classes so I guess that was why.

TL/SKT
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-07-06 15:00:11
July 06 2017 14:54 GMT
#17935
if you have an undirected graph and choose to represent it with an adjacency list

how do we avoid having to traverse two lists whenever an edge is altered?

for example when vertex 3 connects to vertex 7

We need to go to index 3 of our list, find the edge to 7, and alter it
Then we need to go to index 7, find the edge to 3, and alter it

how to avoid this redundancy?


edit: would you use pointers? are there any other ways?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-07-06 15:16:23
July 06 2017 15:05 GMT
#17936
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17247 Posts
Last Edited: 2017-07-06 15:58:15
July 06 2017 15:56 GMT
#17937
Somewhat related, interesting nevertheless:
https://blogs.msdn.microsoft.com/mvpawardprogram/2012/06/25/hierarchies-convert-adjacency-list-to-nested-sets/
Time is precious. Waste it wisely.
slmw
Profile Blog Joined October 2010
Finland233 Posts
July 06 2017 21:02 GMT
#17938
On July 06 2017 23:54 travis wrote:
edit: would you use pointers? are there any other ways?


Yeah, you can always store a pointer to the mirrored edge in each edge. If you store a list pointer / iterator, you can also do removals without a second traversal.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
July 06 2017 23:30 GMT
#17939
Thoughts? A coworker merges a PR where you completely disagreed with their implementation. One senior/not-really person OK'd the PR but he never leaves comments. How would you handle this?
There is no one like you in the universe.
berated-
Profile Blog Joined February 2007
United States1134 Posts
July 07 2017 00:08 GMT
#17940
On July 07 2017 08:30 Blisse wrote:
Thoughts? A coworker merges a PR where you completely disagreed with their implementation. One senior/not-really person OK'd the PR but he never leaves comments. How would you handle this?


Can you verbalize all the reasons you disagree with their implementation? How much code are we talking about? If it's under a couple hours work, I generally try to rework it in the way that I think that it should be done differently without pushing any code off hours. This has a couple benefits, if you figure out along the way that you've missed some assumptions that are actual trade offs that they already considered, you did so without putting your foot in your mouth first. It also provides the benefit that if it works out as you expected then you would now have a talking point that you can approach, I saw your code but was curious did you consider x or y?

Either way, hopefully you work in an environment where you can freely and openly question why things are done. Seek to understand why they did it their way instead of imposing your own way. If you really think you know better then you should be able to ask them questions that lead them to your own conclusion without making any statements making them defensive. I personally also like to have these meetings 1 on 1 to make people feel less vulnerable and less likely to get defensive.
Prev 1 895 896 897 898 899 1031 Next
Please log in or register to reply.
Live Events Refresh
The PiG Daily
22:50
Best Games of SC
Clem vs ByuN
SHIN vs GuMiho
PiGStarcraft500
LiquipediaDiscussion
SC Evo Complete
22:00
Enki Epic Ser. Taeja vs soO EN
davetesta64
Liquipedia
OSC
20:00
Mid Season Playoffs
Spirit vs GeraldLIVE!
Solar vs ShoWTimE
SteadfastSC165
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft500
Nina 188
SteadfastSC 165
RuFF_SC2 61
Vindicta 21
StarCraft: Brood War
Aegong 78
NaDa 29
Icarus 7
Stormgate
NightEnD10
Dota 2
monkeys_forever755
canceldota169
NeuroSwarm119
League of Legends
JimRising 788
febbydoto14
Super Smash Bros
hungrybox416
Heroes of the Storm
Khaldor130
Other Games
summit1g8761
C9.Mang0195
ViBE145
Trikslyr74
Organizations
Other Games
gamesdonequick43400
BasetradeTV34
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH122
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki21
• Pr0nogo 3
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1985
Other Games
• Scarra743
Upcoming Events
RSL Revival
8h 27m
SHIN vs Clem
Cure vs TBD
FEL
10h 27m
FEL
14h 27m
Gerald vs PAPI
Spirit vs ArT
CSO Cup
14h 27m
BSL20 Non-Korean Champi…
16h 27m
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
DaveTesta Events
16h 27m
Sparkling Tuna Cup
1d 8h
RSL Revival
1d 8h
Classic vs TBD
FEL
1d 13h
BSL20 Non-Korean Champi…
1d 16h
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
[ Show More ]
Wardi Open
2 days
Replay Cast
3 days
WardiTV European League
3 days
PiGosaur Monday
3 days
uThermal 2v2 Circuit
4 days
Replay Cast
4 days
The PondCast
5 days
Replay Cast
5 days
Epic.LAN
6 days
Liquipedia Results

Completed

KCM Race Survival 2025 Season 2
HSC XXVII
NC Random Cup

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.