Блог пользователя yamih23436

Автор yamih23436, история, 3 года назад, По-английски

Saw this problem in a(Leetcode) discussion : https://leetcode.com/discuss/interview-experience/1257566/goldman-sachs-tech-analyst-bengaluru-2021-off-campus-offer

Given 2N words each of length N. We have to arrange all the words in a matrix of size N * N such that all the words can be read in the crossword matrix (horizontally/vertically). Also, find the lexicographically smallest arrangement if many are possible: Not sure about constraints , but is there any better way other than brute force ?

Example:

Input:

N = 3

{$$$abc, bfj, cgk, ade, dfg, ejk$$$}

Output:

$$$abc$$$

$$$dfg$$$

$$$ejk$$$

Any ideas ?

  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится