>this is a leetcode hard

the absolute state of leetshitters

Beware Cat Shirt $21.68 |

Beware Cat Shirt $21.68 |

Skip to content
# >this is a leetcode hard

###

>this is a leetcode hard

the absolute state of leetshitters

Beware Cat Shirt $21.68 |

Beware Cat Shirt $21.68 |

ugh

no wonder theyre getting fired

yeah forreal, this is a light medium and takes like 10 minutes to solve and write down

You guys don't know what you're talking about. Any idiot could solve this. The challenge is figuring out an algorithm with the lowest possible time complexity and space complexity. This seems like one which requires a graph pathfinding. You're not gonna come up with an optimal solution unless you happen to already know about that.

>This seems like one which requires a graph pathfinding.

KEK

Yeah, I began to do leetcode like a week ago and noticed this about many problems. It's easy to come up with a brute force solution but the toughest test cases are big enough that you need to be using a non naive algorithm to not get a timeout.

>This seems like one which requires a graph pathfinding.

Breadth-first search is not impressive.

There's an A* heuristic which is the number of letters that differ.

A* requires binary heaps where you can change key priority, and implementing those yourself is never worth the trouble.

I always import solution.

import a_star

Ah, very cool. Wouldn't have thought about it.

it's all meaningless human coding is a stranded asset an AI will solve this like it's nothing

>stranded asset

You learned that phrase yesterday from a shitpost you dumb homosexual moron

quiet strandee

You seem like the kind of subhuman moron that would spam the red deer shit everywhere a couple years back

do not bore me with boomer lore strandee

leetcode hards are totally random in difficulty. some are trivial and others are absolute bullshit

Pick literally any other one and come brag about your inefficient solution.

Not every problem has the correct difficulty rating

>Not every problem has the correct difficulty rating

but why? it's not that hard to determine difficulty

the difficulty labeling of leetcode problems is inconsistent

>Have you read chapter N of my favorite book on algorithms?

Why is this every leetcode question?

>Well yesterday I learned about graphs, so I'll make a graph problem

>Today I learned about shortest path searching algorithms so I'll include a path you have to follow

O(n)

def transformation_sequence(begin, end):

result = []

diff = [i for i, c in enumerate(begin) if c not in end]

w = begin

for idx in diff:

result.append(w)

w = w[:idx] + end[idx] + w[idx+1:]

return result + [end]

print(transformation_sequence("hit", "cog"))

You didn't understand the problem.

lol i actually misread it

I interpreted it exactly the same way you did at first anon.

filtered, read the problem moron, where the frick is the wordlist?

>HECKIN' SPOON-FEED ME!

sneed

Dear [Candidate's First Name],

Thank you for your interest in the [Position] role at [Company]. We appreciate the time and effort you invested in applying for this position.

After careful consideration, we have decided not to move forward with your application at this time. We received a significant number of applications from qualified candidates like yourself, making this selection process extremely difficult.

>didn't even understand the question

>timeout tier

>stack overflow tier

Holy shit you're moronic.

tier

It's not gonna timeout because it has early return and memorization, brainlet

It's "memoization", dumbass. And it's not gonna save you from having the wrong time complexity.

>It's "memoization", dumbass. And it's not gonna save you from having the wrong time complexity.

Let's see your solution then

A brute force solution to this problem seems immediately obvious, but the brute force solution has big O complexity of O(n!) where n is the size of wordList. For larger wordList sizes your program will timeout and the solution will not be accepted.

the optimal solution has worst case O(n*avg(word.length)) time complexity

i am like the anti-coder in terms of coding but even i think this seems to be on the easier side.

here's the solution for brainlets btw

fun diffOne(a: String, b: String): Boolean {

var counter = 0

for (i in a.indices) {

if (a[i] != b[i]) {

if (++counter == 2) return false

}

}

return counter == 1

}

fun transformationLength(beginWord: String, endWord: String, wordList: List<String>): Int {

val visited = BooleanArray(wordList.size)

val queue: Queue<String> = LinkedList()

queue.offer(beginWord)

var depth = 1

while (queue.isNotEmpty()) {

for (i in queue.indices) {

val item = queue.poll()

if (item == endWord) return depth

for ((index, word) in wordList.withIndex()) {

if (visited[index]) continue

if (diffOne(item, word)) {

queue.offer(word)

visited[index] = true

}

}

}

depth++

}

return 0

}

Literally just breadth-first search.

Yup + memorization and proceed to next level based on condition

Hilarious that it qualifies as an LC hard

ITT: homosexual moron nocoders pretend to know how to answer LC hard with stolen LC answers provided by fricking Sandeep

such difficulty

>Recursion

Solution invalid, I'm sorrybanon

it wasn't mentioned in the specification that certain techniques can not be used, nor any space, time, or complexity requirement

>it wasn't mentioned in the specification that certain techniques can not be used, nor any space, time, or complexity requirement

It's doesn't matter what the requirements are, dfs is not the optimal solution and your implementation will probably ACK for any word list bigger than 15 kek

Yes that's something shitty about leetcode. I don't know of any site that does at least some empirical evaluation of your time complexity (gbench can do it).

But in interviews it always matters, obviously. You're not necessarily given the target, you're supposed to find an optimal solution yourself.

>But in interviews it always matters

let me rephrase that

it only matters in interviews

for real jobs noone ever judges your code on complexity

>anon can you estimate how long this module/project will take to code?

>well, it will take 2 hours to code and then another 6 hours to optimize for O(n log(n)) time complexity and O(n) memory complexity ;^)

>... yeah just do it in 2 hours, there is more work to be done

Not true, I could get one of my coworkers fired because of how poorly his code performs.

>muh personal anecdote

85 IQ

>for real jobs noone ever judges your code on complexity

lol

Stick to webshit.

The example is wrong, hog is a word

meds

read the problem again

Yes, this task DOES belong to the hard category.

Were you able to get an AC verdict or are you just bragging that you how fricking high iq you are that you were able to undrstand the problem?

What is your Codeforces rating?

>Bragging about knowing bfs

KEK

Here, an actual leetcode hard, little babby. Now solving THIS, you can be proud of.

https://leetcode.com/problems/trapping-rain-water-ii/

>Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.

And this should be hard?

You literally drop a seed on the highest place from top which is O(n*m) and do a flood fill, and stop when any of the 6 sides except the top and bottom had air (nothing and neighbour) which is easy to model with a boolean matrix. You just add up the correct cube count during flood fill.

You didn't answer my question, what is your Codeforces rating?

>flood fill

Opinion discarded lmfao

Problem with it? This can be imagined as a grid graph, you cannot discover the holes in less than O(x*y*z) where x,y and z are the dimensions of the map, and my algorithm runs in exactly this time complexity. So you don't do Codeforces, Atcodet, IOI nor ICPC and haven't read CP3. The only thing I don't get then is why are you pretending to be smart on the internet? You've posted 2 problems with the text "too easy for me", while not coding a single line, not having a single idea for an algorithm not even speaking of an AC verdict. Solve this fricking exercise, then solve the next and then a 100 more, be smart in your head, not on the internet.

>in college took to algorithms like a fish to water, had zero issues implementing all of them just from high level descriptions

>now after 5 years in the industry I can barely implement sorting and get confused with even easy leetcodes

Wtf happened

Turns out software engineering has a lot more components than "I HAVE THREE METHSTEEKS" Layton-tier brain teasers, so you just forget.