instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a JavaScript function to capitalize the first letter of each word in a string. Additionally, convert all lowercase letters to uppercase and all uppercase letters to lowercase for all other characters in the string. If a word starts with a vowel, capitalize the entire word. If a word ends with a punctuation mark, ... | codefeedback |
Write a JavaScript function that takes in an array of positive integers and removes the last element from the array without using any built-in methods like .pop() or .slice(). Then, calculate the sum of the remaining elements in the array. Your function should return this sum. Additionally, your function should handle ... | codefeedback |
What is the largest prime factor of the number 5,543 that is greater than 1,000? | codefeedback |
Create a function in Python which takes two parameters, a and b, and returns their product. However, the function should raise a ValueError if either of the parameters is not a positive integer. Additionally, the function should only allow inputs within a specified range of 1 to 1000 (inclusive) for both parameters. | codefeedback |
Write a code to delete all the vowels and any word that starts with a vowel from a given string, ensuring that the remaining words are sorted in descending order based on their lengths.
string = "hello world, how are you?" | codefeedback |
Write a code to remove the duplicates from a given list without using any built-in functions or data structures such as sets or dictionaries. The input list can contain any type of elements, including nested lists, and the order of the elements should be preserved in the output. Additionally, your solution should have ... | codefeedback |
Write a code to create a 3 x 3 matrix containing all 0s, but the matrix must be initialized using a recursive algorithm instead of a simple loop. Additionally, the recursive algorithm should use a depth-first search approach to populate the matrix, where each element is randomly assigned either 0 or 1. | codefeedback |
Write a code to find the maximum in a given list of integers. However, you are not allowed to use any loops, built-in functions, or methods to solve this problem. | codefeedback |
Write a code to merge two given lists of equal size into a new list, such that the resulting list contains alternating elements from the two lists. However, the code should not use any additional memory to create the new list. Instead, it should modify the first list in-place to achieve the desired result.
Example:
li... | codefeedback |
Write a code to check whether two strings are anagrams or not. The strings may contain upper and lower case alphabets, numbers, and special characters. The code should also handle strings with whitespace characters.
Example:
first = "LiSt En!@12"
second = "Silent 21@$"
Note: The code should consider all characters in... | codefeedback |
Please write a function in Java that takes two strings as parameters and returns true if the first string is a substring of the second. Additionally, the function should also return true if the first string is a subsequence of the second string.
A subsequence is defined as a sequence that can be derived from another s... | codefeedback |
Create a class in Python to represent a Person. The Person class should have the following attributes and methods:
Attributes:
1. Name: A string representing the person's name.
2. Age: An integer representing the person's age.
3. Height: A float representing the person's height in meters.
4. Weight: A float representi... | codefeedback |
Write a function that sorts the given list of numbers in descending order, but without using any built-in sorting functions or libraries. The function should also handle duplicate numbers in the list and sort them based on their original positions. Additionally, the function should be able to handle lists that contain ... | codefeedback |
Create a program to find the smallest prime factor of a given number. If the number itself is prime, the program should output the number itself.
Input: 24 | codefeedback |
Create a function that takes in a string and returns a dictionary containing the key-value pair of each unique character in the string, along with the frequency of each character. The string may contain punctuation marks, capital letters, and special characters. The function should ignore case sensitivity, meaning that... | codefeedback |
Create a program to create a list of all the prime numbers between 1 and 1000, and then find the sum of all the prime numbers in the list. | codefeedback |
Create a program to classify whether the given number is divisible by 3 or not. However, you are not allowed to use the modulus operator (%) or any built-in functions to solve this problem. The program should take an integer input and print "Divisible by 3" if the number is divisible by 3, and "Not divisible by 3" othe... | codefeedback |
Create a program that converts the input sentence to Pig Latin, while also handling punctuation marks, capitalization, and a maximum word length of 10 characters.
The Pig Latin rules are as follows:
1. If a word begins with a vowel, add "way" to the end of the word.
2. If a word begins with a consonant, move the conso... | codefeedback |
Create a program that extracts a given pattern from a given string. The pattern can be a single character or a substring. If the pattern is a single character, it should only match when it is surrounded by spaces or punctuation marks.
Example:
text = "Hello world!", pattern = "lo"
Expected output: "lo" | codefeedback |
Create a program to check if a given string is a palindrome. The string may contain uppercase and lowercase letters, numbers, and special characters. The program should ignore any spaces or punctuation marks and only consider the alphanumeric characters in the string. The program should also handle strings with a lengt... | codefeedback |
Create a program to generate the sum of all the elements in a given list, but with the following constraints:
1. The program should only use bitwise operations (e.g., bit shifting, bitwise AND/OR/XOR) to perform the addition operation.
2. The program should handle large input lists with thousands or millions of element... | codefeedback |
Create a program to generate all possible pairs of a given list of numbers where the sum of each pair is a prime number. Additionally, ensure that each pair consists of two unique numbers from the given list and the pairs are sorted in ascending order. | codefeedback |
Write a Python program to split a given string into a list of substrings, using any special characters or digits present in the string as delimiters.
#Example#
Input:
string = "Hello@#World123Test"
Output:
["Hello", "#", "World", "123", "Test"]
#Requirements#
- The program should be able to handle strings with any co... | codefeedback |
Create a program to compute the checksum of a given data packet and return the complement of the checksum. The data packet is represented as a list of hexadecimal numbers.
data_packet = [0xff, 0x0a, 0x1b, 0x3f]
The checksum should be calculated as follows:
1. Initialize a variable called `checksum` to 0.
2. For each ... | codefeedback |
Create a program that implements a more complex logic for the given switch statement.
Extend the switch statement to include additional cases, such as case 3, case 4, and so on. Each case should call a different function, such as func3(), func4(), and so on.
Additionally, modify the program to include a default case... | codefeedback |
Generate an NxN array with all its elements equal to 1, ensuring that each row and column sum up to N. The array should be generated in such a way that the time complexity is less than O(N^2). | codefeedback |
Rewritten Test:
Given a list of numbers, find the indices of all occurrences of the second greatest value. If there are multiple occurrences of the second greatest value, return a list of all indices. Otherwise, return a list with a single index.
lst = [3, 5, 6, 8, 9, 9] | codefeedback |
Find the total number of elements in a given multi-dimensional array. The array may contain integers, nested arrays, and even other data types such as strings or booleans. The elements can be located at any depth within the array structure. The array can have a maximum depth of 5 levels. | codefeedback |
Write a function to compare two strings and return True if they are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should ignore any spaces and capitalization. The function should have a time complexity of O(n log n), where n is the length of the input... | codefeedback |
Create a JavaScript function that finds the shortest word in a string, excluding words that contain any uppercase letters or special characters. The function should return the shortest word that is longer than 3 characters and has at least one vowel. The string may contain punctuation marks, multiple spaces between wor... | codefeedback |
Write a SQL query to find the names, job titles, and salaries of all employees working at a given department, sorted by salary in descending order. Additionally, include the average salary of all employees in the same department in the result set. | codefeedback |
Implement a sentiment analysis model that accurately classifies the sentiment of the given sentence, taking into account various factors such as sarcasm, irony, and subtle nuances that may affect the sentiment classification. The model should incorporate a machine learning algorithm and demonstrate high accuracy in sen... | codefeedback |
Write a code to take two string inputs, str1 and str2, where the length of str1 is equal to the length of str2. The code should generate the output string containing alternate characters from each string, but the output string should not contain any repeated characters.
The code should also ensure that the output stri... | codefeedback |
Write a code to check whether the input string is a palindrome or not. However, you are not allowed to use any additional data structures (such as arrays or stacks) and you must solve the problem in-place with constant extra space. The solution should have a time complexity of O(n), where n is the length of the input s... | codefeedback |
Create a web page with a centered title and paragraph in HTML. Additionally, add a button that changes the background color of the page when clicked.
1. The title should be centered horizontally and vertically on the page.
2. The paragraph should also be centered horizontally and vertically on the page, below the tit... | codefeedback |
Change the following array so that it orders in ascending order. The array may contain duplicate elements.
# Reference Erroneous Code #
```
array = [3, 7, 1, 8, 4]
for i in range(len(array)-1):
for j in range(i+1, len(array)):
if array[i] > array[j]:
temp = array[i]
array[i] = array... | codefeedback |
Write a Java program to print out the first n prime numbers, where n must be a positive integer greater than 1 and less than or equal to 1000. The program should also ensure that the user provides a valid input by repeatedly asking for a valid value of n until it is provided. Additionally, the program should calculate ... | codefeedback |
Write a code to compare two lists and find the common elements, taking into consideration that both lists can contain duplicate elements and the output should only include the common elements once. Additionally, the code should have a time complexity of O(n+m), where n and m are the lengths of the two lists.
list1 = ... | codefeedback |
Write an algorithm to check if an array contains a given value and return its index. If the value is not found, return -1. The array can contain duplicate values. | codefeedback |
Write a Django Model API to store status, published date, and author information for a blog post. Additionally, the API should include methods to retrieve all blog posts published within a given date range, to retrieve the total number of published blog posts for each author, and to retrieve the average length of the b... | codefeedback |
Connect to a MySQL database and select all rows from Customers where Phone is greater than 1000, Country is "USA", and OrderDate is between January 1, 2022, and February 28, 2022. Additionally, sort the results in descending order based on the CustomerName and limit the output to only the first 10 rows. | codefeedback |
Write a function to determine if two strings are anagrams of each other. The function should have a time complexity of O(n), where n is the length of the strings. The function should also use constant space, meaning it should not use additional data structures besides a few variables for counting purposes. Additionally... | codefeedback |
Change the following array so that it only contains prime numbers. Additionally, the solution should not use any built-in prime number checking functions or libraries.
mylist = [2, 4, 5, 6, 7, 11, 12, 22] | codefeedback |
Write efficient C++ code to find the maximum subarray sum of a given array, taking into consideration that the array can contain both positive and negative integers. The code should also keep track of the starting and ending indices of the subarray that results in the maximum sum. Additionally, the code should handle t... | codefeedback |
Connect to a MongoDB database, select all documents from the collection ‘customers’ where the 'age' field is greater than 30 and the 'gender' field is 'female', and display the documents in ascending order based on the 'last_name' field. | codefeedback |
Write a function to remove duplicate items in a list. However, the function should only remove duplicates if they appear consecutively in the list. For example, if the list is [2, 3, 3, 4, 5, 6, 4, 7], the function should return [2, 3, 4, 5, 6, 4, 7].
Additionally, the function should also return the number of times e... | codefeedback |
Read the following two JSON strings and merge them. Print the merged JSON. The merged JSON should include all the key-value pairs from both json1 and json2. If a key exists in both JSONs, the value from json2 should overwrite the value from json1. If a key exists in only one JSON, it should be included as is in the mer... | codefeedback |
Write a recursive algorithm to generate the Fibonacci series up to the nth term. Additionally, implement a memoization technique to optimize the algorithm's performance. The memoization technique should use a custom data structure instead of a built-in data structure like a dictionary or hashmap. The custom data struct... | codefeedback |
Write a code to delete all items from a list with a value of 3 and calculate the sum of the remaining items. Also, make sure to handle cases where the list is empty or contains only items with a value of 3. The time complexity of your solution should be O(n), where n is the length of the list. Additionally, you should ... | codefeedback |
Read a code and find all the function calls that are made, while also tracking the number of times each function is called. The code may contain nested function calls and function calls with varying numbers of arguments.
Sample Input:
```python
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def... | codefeedback |
Parse the string "Hello[1]World[4]123[3]" into a list, where the numbers inside the square brackets indicate the number of times the preceding word should be repeated. If a number is not specified, the default repetition is 1. The words and their repetitions should be stored in a dictionary, where the words are the key... | codefeedback |
Write a calculator program that takes in two numbers and performs basic arithmetic operations (addition, subtraction, multiplication, division). The program should include error handling for invalid inputs, division by zero, and also implement a memory feature where the user can store and retrieve previous results. Add... | codefeedback |
Create a doubly linked list node with the data of type integer. The node should have a reference to the next node and a reference to the previous node. Additionally, the node should have a method to insert a new node after it, a method to delete itself from the list, and a method to find the previous node of a given da... | codefeedback |
Find the number of times a letter appears in a string, ignoring case sensitivity. The string may contain alphanumeric characters, spaces, and special characters. The letter can be a single character or a substring. Return the count of occurrences as well as the indices at which the letter/substring appears in the strin... | codefeedback |
Write a code snippet to return the key(s) with the highest value in a given dictionary. If multiple keys have the same highest value, return all of them in a list. The dictionary may contain both positive and negative values.
Example:
d = {'a': 20, 'b': 10, 'c': 15, 'd': -5, 'e': 20, 'f': 15}
Expected output: ['a', 'e... | codefeedback |
Estimate the time complexity of the following algorithm, considering that n must be greater than or equal to 100 and less than or equal to 1000. Additionally, the algorithm should be modified to only print the sum if it is a prime number. The algorithm should also ensure that the sum is computed using a recursive funct... | codefeedback |
For the following two arrays, create a code snippet to return the intersecting element. The solution must have a time complexity of O(n), where n is the length of the arrays, and must not use any built-in intersection functions or data structures. Additionally, the code snippet should be implemented using only constant... | codefeedback |
Generate a unique and random password for a user using Python. The password must meet the following criteria:
1. The password must be at least 12 characters long.
2. The password must contain at least one uppercase letter, one lowercase letter, one number, and one special character.
3. The password must not contain any... | codefeedback |
Write a function that finds the longest string in a list of strings, excluding any strings that contain numbers or special characters. The function should have a time complexity of O(n), where n is the total number of characters in all the strings combined, and you should not use any built-in functions or libraries tha... | codefeedback |
Given a string, write a function to remove all the duplicate characters and return the resulting string. The input string may contain any ASCII characters.
Write a function named "removeDuplicates" that takes a string "s" as input and returns a string.
The function should iterate through each character in the string ... | codefeedback |
Implement a function to extract the last three words from a string of words, where the string contains at least five words and each word is separated by a single space. The function should ignore any leading or trailing spaces in the input string.
Note: The function should have a time complexity of O(n), where n is th... | codefeedback |
Given a binary tree, write a code snippet to list all of its descendant nodes that are at an even level and whose values are divisible by a prime number. | codefeedback |
Write a function to remove all occurrences of a given element from a list while maintaining the original order of the remaining elements. The function should have a time complexity of O(n) and should not use any built-in functions or libraries to remove the elements.
Additionally, you are not allowed to create a new l... | codefeedback |
Write a function to find the intersection of two sorted lists. The intersection should contain only unique elements and should be sorted in ascending order. The input lists may contain duplicate elements, but the intersection should only include unique elements.
list1 = [1, 3, 3, 4, 6, 8, 9, 9]
list2 = [1, 2, 3, 5, 6,... | codefeedback |
Implement a sentiment analysis model that can classify the sentiment of a given sentence as positive, negative, or neutral. The model should be able to handle sentences of varying lengths and complexities. However, the model should be optimized to have a time complexity of O(n) and a space complexity of O(1), where n i... | codefeedback |
Design a function in Python that returns the k-th smallest element in an array of integers. The array may contain duplicates and the function should handle both positive and negative integers. The function should have a time complexity of O(nlogn) and space complexity of O(1).
Note: You can assume that the value of k ... | codefeedback |
Reorder a given array in specialized order while maintaining the relative order of prime and non-prime numbers. | codefeedback |
Create a Ruby program to check if a number is prime or not, but you cannot use any mathematical formulas or predefined functions for prime number calculation. | codefeedback |
Implement a matrix multiplication algorithm using recursion, but with the additional requirement that the algorithm must be optimized to handle large matrices efficiently. | codefeedback |
Generate a random even integer between 1 and 100, and then print the following statements based on the generated number:
- If the number is less than or equal to 50, print "Low even number".
- If the number is greater than 50 and less than or equal to 75, print "Medium even number".
- If the number is greater than 75, ... | codefeedback |
Increase the difficulty by requiring the function to calculate the sum of only even numbers in the input list.
Redesign the following Python program with functions.
Create a function called "calculate_sum" that takes in a list of numbers as a parameter.
Inside the function, initialize a variable called "total" to 0.
I... | codefeedback |
Design a data structure that efficiently stores an array of words, where each word is stored in a Trie data structure. The data structure should support the following operations:
1. `insert(word)`: Inserts a new word into the data structure.
2. `search(word)`: Returns true if the word exists in the data structure, fal... | codefeedback |
Create a function to generate a random password of length n, where n is the number of characters in the password.
Additional Requirements:
1. The password should contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
2. The function should ensure that no two adjacent charact... | codefeedback |
Calculate the sum of an array of integers, but you are not allowed to use the built-in sum() function or any loop structures. | codefeedback |
Write a JavaScript code to valid a password based on the following rules:
1. The password must be at least 10 characters long.
2. The password must contain at least one uppercase letter and one lowercase letter.
3. The password must contain at least one special character (!@#$%^&*).
4. The password must not contain an... | codefeedback |
Find the smallest element in a given array of positive integers, where the array length is between 1 and 100, and the values are between 1 and 1000. Implement the solution using a divide and conquer approach. [6, 8, 1, 4, 5] | codefeedback |
Debug the following JavaScript code which calculates the median of an array of integers. The median is the middle value of a sorted array. If the array has an odd length, the median is the value at the center position. If the array has an even length, the median is the average of the two middle values.
arr = [2, 3, 4,... | codefeedback |
Write a function that determines if a given number is a prime number, while ensuring the time complexity is less than or equal to O(sqrt(n)). Additionally, the function should also output the prime factors of the number if it is not a prime number. | codefeedback |
#Modified Test#
Use the list comprehension syntax to make a new list whose elements are the squares of the odd numbers in the first list. The first list should contain both even and odd numbers.
lst = [1, 2, 3, 4, 5, 6] | codefeedback |
Create a function to reverse a string in-place (i.e., without using any extra space) while also ensuring that all characters are shifted to their next lexicographically greater character. The function should handle both uppercase and lowercase letters. The reversed string should have all vowels capitalized and all cons... | codefeedback |
Write a Python function to calculate the factorial of a number (a non-negative integer). However, you are not allowed to use the built-in `math.factorial()` function.
In addition, you should implement the function iteratively instead of recursively.
You should also optimize the function to have a time complexity of O... | codefeedback |
Design an HTML form with the following fields: first name, last name, age, phone number, address, and email. The form should also include validation for each field, ensuring that the first name and last name are both at least 2 characters long, the age is a positive integer less than or equal to 100, the phone number f... | codefeedback |
Normalize a given array of integers such that it adds up to the nearest prime number greater than the sum of all elements in the array.
#Explanation#
1. Take an array of integers as input.
2. Calculate the sum of all elements in the array.
3. Find the nearest prime number greater than the sum calculated in step 2.
4. ... | codefeedback |
Write a function that takes a string and returns a boolean based on whether the string is a palindrome or not. The function should ignore any non-alphabetic characters, should be case-sensitive, and should also consider numbers and special characters as part of the palindrome check. Additionally, the function should ha... | codefeedback |
Find the top 10 most common words in a given string, while also excluding any common stop words such as "the", "and", "a", "is", etc. Additionally, ensure that the solution runs in O(n) time complexity, where n is the length of the input string.
#Erroneous Code Reference#
Find the top 10 most common words in a given s... | codefeedback |
Write a function to calculate the arithmetic mean of an array of numbers, but the array may contain negative numbers as well.
arr = [5, -8, 2, 4, -7, 10]
#Erroneous Code#
def calculate_mean(arr):
total = 0
for num in arr:
total += num
mean = total / len(arr) + 1 # Added 1 to increase misdirection
... | codefeedback |
Write code to find the longest substring of unique characters in a given string, without using any built-in string functions or data structures. The solution should have a time complexity of O(n).
string = 'abcabcbb'
In addition to finding the longest substring, please also print the starting and ending indices of th... | codefeedback |
Write a function that takes in two strings as input and concatenates them together. The concatenated string should only include characters that are present in both input strings, and the order of characters should be based on the order they appear in the first string. If a character is repeated in the first string, it ... | codefeedback |
Find the longest common substring between two strings, case-insensitive.
s1 = "Tangible"
s2 = "Non-Tangible"
Note: A substring is a contiguous sequence of characters within a string.
You are required to implement a function called "longest_common_substring" that takes two strings as input and returns the longest co... | codefeedback |
Write a code to check whether a given year is a leap year or not and find the number of leap years between a given range of years. Additionally, calculate the average number of leap years per decade within the given range.
To solve the problem, follow these steps:
1. Take the input range of years from the user.
2. Cr... | codefeedback |
How do you declare a variable in Python and assign it a value greater than 100, using only integers and without using any arithmetic operators or built-in functions? | codefeedback |
Find the index of a given item in an array, but the array may contain duplicate items. If the item appears multiple times in the array, return the index of the first occurrence. You need to implement the solution without using any built-in functions or libraries that directly solve the problem, such as the "index" meth... | codefeedback |
Create a program which will take the user's full name (including first name, middle name, and last name) and output a custom message depending on the supplied name. The custom message should be generated based on the following criteria:
- If the first name starts with a vowel and has more than 3 characters, the message... | codefeedback |
Classify a given sentence based on the intention behind it, considering multiple possible intentions, complex grammatical structures, and potential ambiguity or conflicts in intentions.
The program should analyze the sentence and determine the intention behind it by considering various possibilities, such as expressin... | codefeedback |
Create a program to display all prime numbers between a given range, with the additional requirement that the program should also check for palindromic primes. However, the program should exclude all prime numbers that are also perfect squares.
a, b = 2, 100
**Erroneous Code Reference:**
```
def is_palindrome(n):
... | codefeedback |
Write a SQL query to select the top 5 highest salaries in a employees table, excluding any salaries that are equal to or lower than $100,000. Additionally, include the department name for each employee in the result set. | codefeedback |
Implement a function that calculates the Big O notation for a given algorithm's time complexity, but the algorithm must be a combination of both recursive and iterative approaches. Return a string representation of the result. | codefeedback |
Write a Python function to check if a value exists in a list of integers, and return the number of occurrences of that value in the list. However, you are not allowed to use any built-in Python functions or libraries such as "in", "count", or "collections". You must implement your own logic to achieve the desired resul... | codefeedback |
Please write code to implement the Odd-Even Sort algorithm.
Additional requirements:
- The sorting algorithm should be implemented as a function.
- The function should take an array of integers as input and return the sorted array.
- The function should handle arrays of any length.
- The function should handle arrays ... | codefeedback |
Write a code to multiply two numbers without using the multiplication operator. Additionally, you are not allowed to use any looping constructs (e.g. for loop, while loop) or any built-in functions or methods that directly perform multiplication.
Furthermore, you are now required to handle decimal numbers as inputs an... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.