Skip to content

Instantly share code, notes, and snippets.

@dre4success
Last active July 22, 2019 17:21
Show Gist options
  • Save dre4success/088aa230f34e106188c891600042ee13 to your computer and use it in GitHub Desktop.
Save dre4success/088aa230f34e106188c891600042ee13 to your computer and use it in GitHub Desktop.
Given an unsorted array of n elements, find if the element k is present in the given array or not. return 'YES' or 'NO'
{"lastUpload":"2019-07-22T17:21:44.605Z","extensionVersion":"v3.4.1"}
[
{
"metadata": {
"id": "f583eafd-aa0d-4ccb-8f44-d1e610389660",
"publisherId": "CoenraadS.bracket-pair-colorizer",
"publisherDisplayName": "CoenraadS"
},
"name": "bracket-pair-colorizer",
"publisher": "CoenraadS",
"version": "1.0.61"
},
{
"metadata": {
"id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd",
"publisherId": "Shan.code-settings-sync",
"publisherDisplayName": "Shan"
},
"name": "code-settings-sync",
"publisher": "Shan",
"version": "3.4.1"
},
{
"metadata": {
"id": "532533c9-a894-4a58-9eee-bbfbe7c06f71",
"publisherId": "mikestead.dotenv",
"publisherDisplayName": "mikestead"
},
"name": "dotenv",
"publisher": "mikestead",
"version": "1.0.1"
},
{
"metadata": {
"id": "d6f6cfea-4b6f-41f4-b571-6ad2ab7918da",
"publisherId": "ms-vscode.Go",
"publisherDisplayName": "ms-vscode"
},
"name": "Go",
"publisher": "ms-vscode",
"version": "0.11.4"
},
{
"metadata": {
"id": "3b1db1fc-c7f7-4bd6-9fa4-b499dfa99a8a",
"publisherId": "shd101wyy.markdown-preview-enhanced",
"publisherDisplayName": "shd101wyy"
},
"name": "markdown-preview-enhanced",
"publisher": "shd101wyy",
"version": "0.4.3"
},
{
"metadata": {
"id": "e58f546c-babc-455f-a265-ba40dbd140d4",
"publisherId": "sdras.night-owl",
"publisherDisplayName": "sdras"
},
"name": "night-owl",
"publisher": "sdras",
"version": "1.1.3"
},
{
"metadata": {
"id": "dff6b801-247e-40e9-82e8-8c9b1d19d1b8",
"publisherId": "christian-kohler.npm-intellisense",
"publisherDisplayName": "christian-kohler"
},
"name": "npm-intellisense",
"publisher": "christian-kohler",
"version": "1.3.0"
},
{
"metadata": {
"id": "b027c4b2-25ad-46db-b574-05dae3b2dc92",
"publisherId": "azemoh.one-monokai",
"publisherDisplayName": "azemoh"
},
"name": "one-monokai",
"publisher": "azemoh",
"version": "0.3.7"
},
{
"metadata": {
"id": "96fa4707-6983-4489-b7c5-d5ffdfdcce90",
"publisherId": "esbenp.prettier-vscode",
"publisherDisplayName": "esbenp"
},
"name": "prettier-vscode",
"publisher": "esbenp",
"version": "1.9.0"
},
{
"metadata": {
"id": "f1f59ae4-9318-4f3c-a9b5-81b2eaa5f8a5",
"publisherId": "ms-python.python",
"publisherDisplayName": "ms-python"
},
"name": "python",
"publisher": "ms-python",
"version": "2019.6.24221"
},
{
"metadata": {
"id": "7f7e0e9c-b5ad-4e21-a425-f63bd56cb13f",
"publisherId": "EQuimper.react-native-react-redux",
"publisherDisplayName": "EQuimper"
},
"name": "react-native-react-redux",
"publisher": "EQuimper",
"version": "2.0.3"
},
{
"metadata": {
"id": "e5fd2b56-1637-4d4f-8252-6c9d416f9a28",
"publisherId": "RobbOwen.synthwave-vscode",
"publisherDisplayName": "RobbOwen"
},
"name": "synthwave-vscode",
"publisher": "RobbOwen",
"version": "0.0.7"
},
{
"metadata": {
"id": "87f8f7cb-58d6-4278-8d50-534e05e14814",
"publisherId": "ulthes.theme-firewatch",
"publisherDisplayName": "ulthes"
},
"name": "theme-firewatch",
"publisher": "ulthes",
"version": "1.0.3"
},
{
"metadata": {
"id": "f5d7ffda-c1d6-4070-ba80-803c705a1ee6",
"publisherId": "monokai.theme-monokai-pro-vscode",
"publisherDisplayName": "monokai"
},
"name": "theme-monokai-pro-vscode",
"publisher": "monokai",
"version": "1.1.13"
},
{
"metadata": {
"id": "1b160753-ae5e-42bb-82ad-d115ce5c10f4",
"publisherId": "be5invis.vscode-custom-css",
"publisherDisplayName": "be5invis"
},
"name": "vscode-custom-css",
"publisher": "be5invis",
"version": "3.0.4"
},
{
"metadata": {
"id": "583b2b34-2c1e-4634-8c0b-0b82e283ea3a",
"publisherId": "dbaeumer.vscode-eslint",
"publisherDisplayName": "dbaeumer"
},
"name": "vscode-eslint",
"publisher": "dbaeumer",
"version": "1.9.0"
},
{
"metadata": {
"id": "55ef6448-487b-49a0-a66e-4d2d9bb82229",
"publisherId": "Prisma.vscode-graphql",
"publisherDisplayName": "Prisma"
},
"name": "vscode-graphql",
"publisher": "Prisma",
"version": "0.2.1"
},
{
"metadata": {
"id": "9ccc1dd7-7ec4-4a46-bd4f-7d7b8b9d322a",
"publisherId": "vscode-icons-team.vscode-icons",
"publisherDisplayName": "vscode-icons-team"
},
"name": "vscode-icons",
"publisher": "vscode-icons-team",
"version": "8.8.0"
},
{
"metadata": {
"id": "c46b0018-f317-4b6c-a785-d2039b27338f",
"publisherId": "wix.vscode-import-cost",
"publisherDisplayName": "wix"
},
"name": "vscode-import-cost",
"publisher": "wix",
"version": "2.12.0"
},
{
"metadata": {
"id": "dd7238e4-5ba5-470c-9e3e-07a317efe0da",
"publisherId": "af4jm.vscode-m3u",
"publisherDisplayName": "af4jm"
},
"name": "vscode-m3u",
"publisher": "af4jm",
"version": "1.0.0"
},
{
"metadata": {
"id": "f2fd462f-f1bd-4c62-b54f-59a4e5ffc6a3",
"publisherId": "WakaTime.vscode-wakatime",
"publisherDisplayName": "WakaTime"
},
"name": "vscode-wakatime",
"publisher": "WakaTime",
"version": "2.2.0"
}
]
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+shift+/",
"command": "editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+a",
"command": "-editor.action.blockComment",
"when": "editorTextFocus && !editorReadonly"
}
]
{
"editor.fontFamily": "Fira Code",
"editor.fontSize": 12.5,
"editor.fontLigatures": true,
"workbench.startupEditor": "newUntitledFile",
"window.zoomLevel": 0.5,
"emmet.includeLanguages": {
"javascript": "javascriptreact"
},
"editor.tabSize": 2,
"workbench.colorTheme": "SynthWave '84",
"prettier.singleQuote": true,
"window.title": "${dirty}${activeEditorMedium}${separator}${rootName}${separator}",
"editor.snippetSuggestions": "top",
"emmet.triggerExpansionOnTab": true,
"editor.renderIndentGuides": false,
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"workbench.colorCustomizations": {
"editorLineNumber.activeForeground": "#4477a1",
"titleBar.activeForeground": "#000",
"titleBar.inactiveForeground": "#000000CC",
"titleBar.activeBackground": "#2bd8f3ae",
"titleBar.inactiveBackground": "#3d3b31cc"
},
"explorer.confirmDragAndDrop": false,
"prettier.bracketSpacing": true,
"zenMode.centerLayout": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"editor.formatOnSave": true,
"editor.codeActionsOnSaveTimeout": 3000,
"files.autoSave": "afterDelay",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.iconTheme": "vscode-icons",
"typescript.updateImportsOnFileMove.enabled": "always",
"git.enableSmartCommit": true,
"editor.formatOnPaste": true,
"vscode_custom_css.imports": [
"file:///C:/Users/T460S/synthwave84.css"
],
"vscode_custom_css.policy": true,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"sync.gist": "088aa230f34e106188c891600042ee13"
}
{
// Place your snippets for powershell here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
}
@mariamyousfi
Copy link

I am trying to try your formula with the following explanation

Given the array = [2,3,1] and k = 5. There is no element 5 in the array and therefore we print "NO"

+function findNumber(arr, k) {

  • let result = 'NO';
  • arr.forEach(2,3,1 => {5}
  • if(5 === 2,3,1) {
  •  return result = 'YES';
    
  • }
  • })
  • return result;
    +}

@swethakapa
Copy link

function findNumber(arr, k) {
let result = 'NO';
arr.forEach(item => {
if(k === item) {
return result = 'YES';
}
})
return result;
}

@rawgu1990
Copy link

Can you please help me this code with Python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment