This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Pseudo-Palindromic Paths in a Binary Tree: | |
| Given a binary tree where node values are digits from 1 to 9. | |
| A path in the binary tree is said to be pseudo-palindromic if | |
| at least one permutation of the node values in the path is a palindrome. | |
| Return the number of pseudo-palindromic paths going from the root node to leaf nodes. | |
| Examples 1: | |
| 3 | |
| / \ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | .previewIframe { width: 100vw; height: 100vh; border: 0;} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { connect, ObjectId } from "../../../utils/database"; | |
| // import { connect, ObjectId } from "../../../utils/fakeDatabase"; | |
| export default async (req, res) => { | |
| const { | |
| query: { id }, | |
| method, | |
| } = req; | |
| const collectionName = "pens"; | |
| switch (method) { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | case "POST": | |
| try { | |
| const { html, css, js, id } = req.body; | |
| const { db } = await connect(); | |
| await db | |
| .collection(collectionName) | |
| .updateOne( | |
| { _id: ObjectId(id) }, | |
| { $set: { html: html, css: css, js: js } } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | case "PUT": | |
| try { | |
| const { html, css, js } = req.body; | |
| const { db } = await connect(); | |
| const result = await db.collection(collectionName).insertOne({ | |
| html, | |
| css, | |
| js, | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | case "GET": | |
| try { | |
| const { db } = await connect(); | |
| const data = await db | |
| .collection(collectionName) | |
| .findOne({ _id: ObjectId(id) }); | |
| if (!data) { | |
| res.status(404).json({ success: false }); | |
| } | |
| res.status(200).json({ data }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { connect, ObjectId } from "../../../utils/database"; | |
| # OR fake db | |
| import { connect, ObjectId } from "../../../utils/fakeDatabase"; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { MongoClient, ObjectId } from "mongo-mock"; | |
| async function connect() { | |
| const db = await MongoClient.connect("mongodb://someserver/mock_database"); | |
| const collection = await db.createCollection("pens"); | |
| return {db , collection}; | |
| } | |
| export { connect, ObjectId }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { MongoClient, ObjectId } from "mongodb"; | |
| const dbName = "db-name"; | |
| const url = `mongodb+srv://your-username:your-password@cluster0.ldrfm.mongodb.net/your-db?retryWrites=true&w=majority`; | |
| const client = new MongoClient(url, { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true, | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | .previewIframe { | |
| width: 100vw; | |
| height: 100vh; | |
| border: 0; | |
| pointer-events: none; | |
| } | |
| .loading { | |
| width: 100vw; | |
| height: 100vh; | 
NewerOlder