CoolFace
Datasetpublic

FPEvalDataset/LeetCodeProblem

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes305downloads
1{2    "id": 3439,3    "name": "find_minimum_diameter_after_merging_two_trees",4    "difficulty": "Hard",5    "link": "https://leetcode.com/problems/find-minimum-diameter-after-merging-two-trees/",6    "date": "2024-06-23 00:00:00",7    "task_description": "There exist two **undirected **trees with `n` and `m` nodes, numbered from `0` to `n - 1` and from `0` to `m - 1`, respectively. You are given two 2D integer arrays `edges1` and `edges2` of lengths `n - 1` and `m - 1`, respectively, where `edges1[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi` in the first tree and `edges2[i] = [ui, vi]` indicates that there is an edge between nodes `ui` and `vi` in the second tree. You must connect one node from the first tree with another node from the second tree with an edge. Return the **minimum **possible **diameter **of the resulting tree. The **diameter** of a tree is the length of the _longest_ path between any two nodes in the tree. **Example 1:** **Input:** edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]] **Output:** 3 **Explanation:** We can obtain a tree of diameter 3 by connecting node 0 from the first tree with any node from the second tree. **Example 2:** **Input:** edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]] **Output:** 5 **Explanation:** We can obtain a tree of diameter 5 by connecting node 0 from the first tree with node 0 from the second tree. **Constraints:** `1 <= n, m <= 105` `edges1.length == n - 1` `edges2.length == m - 1` `edges1[i].length == edges2[i].length == 2` `edges1[i] = [ai, bi]` `0 <= ai, bi < n` `edges2[i] = [ui, vi]` `0 <= ui, vi < m` The input is generated such that `edges1` and `edges2` represent valid trees.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]",12            "output": "3 "13        },14        {15            "label": "Example 2",16            "input": "edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]",17            "output": "5 "18        }19    ],20    "private_test_cases": [21        {22            "input": [23                [24                    [25                        40,26                        4127                    ],28                    [29                        26,30                        2731                    ],32                    [33                        56,34                        5735                    ],36                    [37                        62,38                        6339                    ],40                    [41                        24,42                        2543                    ],44                    [45                        27,46                        2847                    ],48                    [49                        21,50                        2251                    ],52                    [53                        44,54                        4555                    ],56                    [57                        76,58                        7759                    ],60                    [61                        60,62                        6163                    ],64                    [65                        58,66                        5967                    ],68                    [69                        7,70                        871                    ],72                    [73                        82,74                        8375                    ],76                    [77                        65,78                        6679                    ],80                    [81                        13,82                        1483                    ],84                    [85                        32,86                        3387                    ],88                    [89                        3,90                        491                    ],92                    [93                        23,94                        2495                    ],96                    [97                        81,98                        8299                    ],100                    [101                        69,102                        70103                    ],104                    [105                        49,106                        50107                    ],108                    [109                        10,110                        11111                    ],112                    [113                        8,114                        9115                    ],116                    [117                        41,118                        42119                    ],120                    [121                        38,122                        39123                    ],124                    [125                        34,126                        35127                    ],128                    [129                        46,130                        47131                    ],132                    [133                        15,134                        16135                    ],136                    [137                        42,138                        43139                    ],140                    [141                        17,142                        18143                    ],144                    [145                        70,146                        71147                    ],148                    [149                        73,150                        74151                    ],152                    [153                        18,154                        19155                    ],156                    [157                        48,158                        49159                    ],160                    [161                        61,162                        62163                    ],164                    [165                        1,166                        2167                    ],168                    [169                        74,170                        75171                    ],172                    [173                        19,174                        20175                    ],176                    [177                        31,178                        32179                    ],180                    [181                        54,182                        55183                    ],184                    [185                        66,186                        67187                    ],188                    [189                        79,190                        80191                    ],192                    [193                        33,194                        34195                    ],196                    [197                        2,198                        3199                    ],200                    [201                        12,202                        13203                    ],204                    [205                        35,206                        36207                    ],208                    [209                        9,210                        10211                    ],212                    [213                        71,214                        72215                    ],216                    [217                        25,218                        26219                    ],220                    [221                        78,222                        79223                    ],224                    [225                        11,226                        12227                    ],228                    [229                        16,230                        17231                    ],232                    [233                        51,234                        52235                    ],236                    [237                        63,238                        64239                    ],240                    [241                        20,242                        21243                    ],244                    [245                        39,246                        40247                    ],248                    [249                        0,250                        1251                    ],252                    [253                        4,254                        5255                    ],256                    [257                        29,258                        30259                    ],260                    [261                        36,262                        37263                    ],264                    [265                        77,266                        78267                    ],268                    [269                        6,270                        7271                    ],272                    [273                        68,274                        69275                    ],276                    [277                        28,278                        29279                    ],280                    [281                        64,282                        65283                    ],284                    [285                        43,286                        44287                    ],288                    [289                        55,290                        56291                    ],292                    [293                        57,294                        58295                    ],296                    [297                        75,298                        76299                    ],300                    [301                        30,302                        31303                    ],304                    [305                        67,306                        68307                    ],308                    [309                        14,310                        15311                    ],312                    [313                        5,314                        6315                    ],316                    [317                        47,318                        48319                    ],320                    [321                        53,322                        54323                    ],324                    [325                        45,326                        46327                    ],328                    [329                        22,330                        23331                    ],332                    [333                        37,334                        38335                    ],336                    [337                        59,338                        60339                    ],340                    [341                        72,342                        73343                    ],344                    [345                        52,346                        53347                    ],348                    [349                        80,350                        81351                    ],352                    [353                        50,354                        51355                    ]356                ],357                [358                    [359                        46,360                        47361                    ],362                    [363                        10,364                        11365                    ],366                    [367                        34,368                        35369                    ],370                    [371                        28,372                        29373                    ],374                    [375                        47,376                        48377                    ],378                    [379                        4,380                        5381                    ],382                    [383                        14,384                        15385                    ],386                    [387                        49,388                        50389                    ],390                    [391                        45,392                        46393                    ],394                    [395                        52,396                        53397                    ],398                    [399                        9,400                        10401                    ],402                    [403                        15,404                        16405                    ],406                    [407                        37,408                        38409                    ],410                    [411                        0,412                        1413                    ],414                    [415                        5,416                        6417                    ],418                    [419                        31,420                        32421                    ],422                    [423                        48,424                        49425                    ],426                    [427                        42,428                        43429                    ],430                    [431                        8,432                        9433                    ],434                    [435                        1,436                        2437                    ],438                    [439                        13,440                        14441                    ],442                    [443                        44,444                        45445                    ],446                    [447                        23,448                        24449                    ],450                    [451                        36,452                        37453                    ],454                    [455                        26,456                        27457                    ],458                    [459                        7,460                        8461                    ],462                    [463                        40,464                        41465                    ],466                    [467                        2,468                        3469                    ],470                    [471                        6,472                        7473                    ],474                    [475                        29,476                        30477                    ],478                    [479                        24,480                        25481                    ],482                    [483                        22,484                        23485                    ],486                    [487                        27,488                        28489                    ],490                    [491                        3,492                        4493                    ],494                    [495                        18,496                        19497                    ],498                    [499                        33,500                        34501                    ],502                    [503                        30,504                        31505                    ],506                    [507                        19,508                        20509                    ],510                    [511                        11,512                        12513                    ],514                    [515                        41,516                        42517                    ],518                    [519                        35,520                        36521                    ],522                    [523                        17,524                        18525                    ],526                    [527                        16,528                        17529                    ],530                    [531                        25,532                        26533                    ],534                    [535                        50,536                        51537                    ],538                    [539                        51,540                        52541                    ],542                    [543                        39,544                        40545                    ],546                    [547                        21,548                        22549                    ],550                    [551                        43,552                        44553                    ],554                    [555                        12,556                        13557                    ],558                    [559                        32,560                        33561                    ],562                    [563                        38,564                        39565                    ],566                    [567                        20,568                        21569                    ]570                ]571            ],572            "output": 83573        },574        {575            "input": [576                [577                    [578                        18,579                        19580                    ],581                    [582                        15,583                        16584                    ],585                    [586                        81,587                        82588                    ],589                    [590                        60,591                        61592                    ],593                    [594                        56,595                        57596                    ],597                    [598                        62,599                        63600                    ],601                    [602                        42,603                        43604                    ],605                    [606                        75,607                        76608                    ],609                    [610                        44,611                        45612                    ],613                    [614                        28,615                        29616                    ],617                    [618                        77,619                        78620                    ],621                    [622                        41,623                        42624                    ],625                    [626                        24,627                        25628                    ],629                    [630                        50,631                        51632                    ],633                    [634                        21,635                        22636                    ],637                    [638                        69,639                        70640                    ],641                    [642                        76,643                        77644                    ],645                    [646                        27,647                        28648                    ],649                    [650                        51,651                        52652                    ],653                    [654                        84,655                        85656                    ],657                    [658                        63,659                        64660                    ],661                    [662                        88,663                        89664                    ],665                    [666                        2,667                        3668                    ],669                    [670                        53,671                        54672                    ],673                    [674                        3,675                        4676                    ],677                    [678                        79,679                        80680                    ],681                    [682                        14,683                        15684                    ],685                    [686                        22,687                        23688                    ],689                    [690                        16,691                        17692                    ],693                    [694                        26,695                        27696                    ],697                    [698                        1,699                        2700                    ],701                    [702                        34,703                        35704                    ],705                    [706                        43,707                        44708                    ],709                    [710                        12,711                        13712                    ],713                    [714                        31,715                        32716                    ],717                    [718                        58,719                        59720                    ],721                    [722                        13,723                        14724                    ],725                    [726                        74,727                        75728                    ],729                    [730                        20,731                        21732                    ],733                    [734                        29,735                        30736                    ],737                    [738                        36,739                        37740                    ],741                    [742                        59,743                        60744                    ],745                    [746                        39,747                        40748                    ],749                    [750                        0,751                        1752                    ],753                    [754                        37,755                        38756                    ],757                    [758                        10,759                        11760                    ],761                    [762                        86,763                        87764                    ],765                    [766                        35,767                        36768                    ],769                    [770                        64,771                        65772                    ],773                    [774                        19,775                        20776                    ],777                    [778                        45,779                        46780                    ],781                    [782                        49,783                        50784                    ],785                    [786                        8,787                        9788                    ],789                    [790                        38,791                        39792                    ],793                    [794                        71,795                        72796                    ],797                    [798                        70,799                        71800                    ],801                    [802                        11,803                        12804                    ],805                    [806                        32,807                        33808                    ],809                    [810                        55,811                        56812                    ],813                    [814                        80,815                        81816                    ],817                    [818                        7,819                        8820                    ],821                    [822                        23,823                        24824                    ],825                    [826                        83,827                        84828                    ],829                    [830                        30,831                        31832                    ],833                    [834                        57,835                        58836                    ],837                    [838                        33,839                        34840                    ],841                    [842                        5,843                        6844                    ],845                    [846                        6,847                        7848                    ],849                    [850                        25,851                        26852                    ],853                    [854                        48,855                        49856                    ],857                    [858                        89,859                        90860                    ],861                    [862                        46,863                        47864                    ],865                    [866                        73,867                        74868                    ],869                    [870                        40,871                        41872                    ],873                    [874                        85,875                        86876                    ],877                    [878                        17,879                        18880                    ],881                    [882                        66,883                        67884                    ],885                    [886                        67,887                        68888                    ],889                    [890                        65,891                        66892                    ],893                    [894                        61,895                        62896                    ],897                    [898                        82,899                        83900                    ],901                    [902                        52,903                        53904                    ],905                    [906                        78,907                        79908                    ],909                    [910                        9,911                        10912                    ],913                    [914                        47,915                        48916                    ],917                    [918                        68,919                        69920                    ],921                    [922                        87,923                        88924                    ],925                    [926                        54,927                        55928                    ],929                    [930                        4,931                        5932                    ],933                    [934                        72,935                        73936                    ]937                ],938                [939                    [940                        55,941                        56942                    ],943                    [944                        12,945                        13946                    ],947                    [948                        36,949                        37950                    ],951                    [952                        17,953                        18954                    ],955                    [956                        2,957                        3958                    ],959                    [960                        18,961                        19962                    ],963                    [964                        29,965                        30966                    ],967                    [968                        50,969                        51970                    ],971                    [972                        25,973                        26974                    ],975                    [976                        39,977                        40978                    ],979                    [980                        52,981                        53982                    ],983                    [984                        13,985                        14986                    ],987                    [988                        31,989                        32990                    ],991                    [992                        59,993                        60994                    ],995                    [996                        46,997                        47998                    ],999                    [1000                        47,1001                        481002                    ],1003                    [1004                        9,1005                        101006                    ],1007                    [1008                        30,1009                        311010                    ],1011                    [1012                        43,1013                        441014                    ],1015                    [1016                        35,1017                        361018                    ],1019                    [1020                        44,1021                        451022                    ],1023                    [1024                        19,1025                        201026                    ],1027                    [1028                        42,1029                        431030                    ],1031                    [1032                        7,1033                        81034                    ],1035                    [1036                        26,1037                        271038                    ],1039                    [1040                        56,1041                        571042                    ],1043                    [1044                        45,1045                        461046                    ],1047                    [1048                        53,1049                        541050                    ],1051                    [1052                        41,1053                        421054                    ],1055                    [1056                        16,1057                        171058                    ],1059                    [1060                        54,1061                        551062                    ],1063                    [1064                        24,1065                        251066                    ],1067                    [1068                        58,1069                        591070                    ],1071                    [1072                        48,1073                        491074                    ],1075                    [1076                        6,1077                        71078                    ],1079                    [1080                        5,1081                        61082                    ],1083                    [1084                        1,1085                        21086                    ],1087                    [1088                        34,1089                        351090                    ],1091                    [1092                        28,1093                        291094                    ],1095                    [1096                        22,1097                        231098                    ],1099                    [1100                        21,1101                        221102                    ],1103                    [1104                        8,1105                        91106                    ],1107                    [1108                        33,1109                        341110                    ],1111                    [1112                        61,1113                        621114                    ],1115                    [1116                        60,1117                        611118                    ],1119                    [1120                        38,1121                        391122                    ],1123                    [1124                        0,1125                        11126                    ],1127                    [1128                        14,1129                        151130                    ],1131                    [1132                        20,1133                        211134                    ],1135                    [1136                        32,1137                        331138                    ],1139                    [1140                        62,1141                        631142                    ],1143                    [1144                        27,1145                        281146                    ],1147                    [1148                        4,1149                        51150                    ],1151                    [1152                        40,1153                        411154                    ],1155                    [1156                        23,1157                        241158                    ],1159                    [1160                        10,1161                        111162                    ],1163                    [1164                        37,1165                        381166                    ],1167                    [1168                        51,1169                        521170                    ],1171                    [1172                        15,1173                        161174                    ],1175                    [1176                        49,1177                        501178                    ],1179                    [1180                        57,1181                        581182                    ],1183                    [1184                        11,1185                        121186                    ],1187                    [1188                        3,1189                        41190                    ]1191                ]1192            ],1193            "output": 901194        },1195        {1196            "input": [1197                [1198                    [1199                        23,1200                        24

Showing the first 1,200 of 2492 lines. Download the file for the rest.