Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh432004 committed Jul 1, 2024
2 parents 168ac39 + 97db97a commit d1338e1
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/npm-grunt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: NodeJS with Grunt

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm install
grunt
36 changes: 36 additions & 0 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test

publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
50 changes: 50 additions & 0 deletions findWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @param {character[][]} board
* @param {string[]} words
* @return {string[]}
*/
var findWords = function(board, words) {
let result = []
let root = buildTrie(words)

for(let i = 0; i< board.length ;i++){
for(let j=0;j<board[0].length;j++){
dfs(root,i,j,result,board)
}
}
return result
};
function dfs(node,i,j,result,board){
if(node.word){
result.push(node.word)
node.word = null
}

if(i<0 || j<0 || i > board.length -1 || j > board[0].length-1) return
if(!node[board[i][j]]) return

let c = board[i][j]
board[i][j] = '#'

dfs(node[c],i+1,j,result,board)
dfs(node[c],i-1,j,result,board)
dfs(node[c],i,j+1,result,board)
dfs(node[c],i,j-1,result,board)
board[i][j] = c

}

function buildTrie(words){
let root = {}

for(let word of words){
let currNode = root

for(let char of word){
if(!currNode[char]) currNode[char] = {}
currNode = currNode[char]
}
currNode.word = word
}
return root
}

0 comments on commit d1338e1

Please sign in to comment.